As you can see in the code sample below, in hopes of getting the sum of all the option_msrp values.
var obj, i, sum;
obj = JSON.parse(socookie);
for(i=0; i<obj.length; i++){
sum += parseInt((obj[i].option_msrp).slice(1));
}
option_msrp
is a string in the following format: "$300" (a dollar sign followed by the dollar value, which is a whole number). I'm trying to convert this string into an integer via parseInt
.
I'm trying to remove the dollar sign from the string to be able to convert this string into an integer.
I've tried the various methods to do this below and none of them have worked:
//doesn't work
sum += parseInt((obj[i].option_msrp).slice(1));
//also doesn't work
sum += parseInt((obj[i].option_msrp).replace("$",""));
What am I doing wrong?