Ответ 1
РЕДАКТИРОВАТЬ: Начиная с ответа теперь, когда у меня есть код, который работает.
Глядя на ваш обновленный код, это должно работать:
Пример: http://jsbin.com/ekege3/
var result = [
buildList($('.productCodeID > .productitemcell'), 'skulist'),
buildList($('.productQuantityID > .productitemcell > input'), 'quantitylist'),
buildList($('.productPriceID > .productitemcell'), 'pricelist')
];
result[ 2 ] = result[ 2 ].replace(/\$/g, '');
var string = result.join('&');
Примечание: Вы можете немного сократить свою функцию buildList
:
function buildList(items, name) {
return (name + '=') + items.map(function() {
return (this.value || $(this).text());
}).get().join(',');
}
Оригинальный ответ:
Если у вас есть строка, просто используйте .replace()
.
var str = "pricelist=$15.00,$19.50,$29.50";
str = str.replace(/\$/g, '');
Или вы говорите, что у вас есть переменная pricelist
, содержащая массив? Если да, сделайте следующее:
var pricelist = ["$15.00","$19.50","$29.50"];
for( var i = 0, len = pricelist.length; i < len; i++ ) {
pricelist[ i ] = pricelist[ i ].replace('$', '');
}
EDIT: Кажется, что метод buildList
возвращает массив.
Один из способов проверки - сделать это:
alert( Object.prototype.toString.call( result[2] ) );
И посмотрите, что он вам дает.
В любом случае, если предположить, что это массив, здесь обновленная версия второго примера.
var result = [
buildList($('.productCodeID > .productitemcell'), 'skulist'),
buildList($('.productQuantityID > .productitemcell > input'), 'quantitylist'),
buildList($('.productPriceID > .productitemcell'), 'pricelist')
];
// verify the data type
alert( Object.prototype.toString.call( result[ 2 ] ) );
// loop over result[ 2 ], replacing the $ with ''
for( var i = 0, len = result[ 2 ].length; i < len; i++ ) {
result[ 2 ][ i ] = result[ 2 ][ i ].replace('$', '');
}
var string = result.join('&');