I collect the current value of a range slider every 1 second and store those values in an array. The value are saved as ["34", "23", "21"]. I need them to save as ints like [6, 4, 3, 2] before I can use them as data in my charts.js canvas. Haven't been able to find a clear answer!
2 Answers
You can use javscript function parseInt() to acheive it
for example:-
var x=["1","2","3","4"]
x.forEach(function(item){
console.log(parseInt(x,10));
});
it will console all numeric values
2 Comments
gafi
always use parseInt with radix spcified
parseInt(x,10) as some old browsers may have unexpected behaviorShubham Nigam
@Gaafar i agree with you,providing radix would be a plus point as exceptional handling point of view.
parseInt()function and store.