I am trying to parse this array of checkbox values and remove the "N".
Using the replace function yields the error TypeError: numberArr[i].replace is not a function, and if I remove the replace function, the script simply outputs NaN for my values.
Fiddle here http://jsfiddle.net/j0w5tkg9/3/
<div id='opts'>
<input type="checkbox" data-cost="0" value="44N12345" name="options[]">
<input type="checkbox" data-cost="0" value="55N6789" name="options[]">
</div>
<div id='output'></div>
function getAllocArray() {
var numberArr = $.map($('input:checkbox:checked'), function (e, i) {
return +e.value;
});
var varOutput = '<ul>';
for (var i = 0, len = numberArr.length; i < len; i++) {
varOutput += "<li>" + numberArr[i].replace(/N/,'') + "</li>";
}
varOutput += '</ul>';
$('#output').text(varOutput);
};
$('#opts').on('click', 'input:checkbox', null, getAllocArray);
parseInt(+e.value)instead of+e.value.parseInt('44N12345')returns44, butNumber('44N12345')returns NaN because there is stringN+operator is what's giving youNaN.