I am trying to convert an array of strings into an array of integers in jquery.
Here is my attempt:
var cdata = data.values.split(",");
$.each( cdata, function(i, l){
l = parseInt(l);
});
I think that you not need use Jquery for this case. In javascript pure:
var str = "1,2,3";
var ArrayOfInts = str.split(',').map(Number); //Output: [1,2,3]
// Use jQuery
$('.usesJQuery');
// Do what you want to acomplish with a plain old Javascript loop
var cdata = data.values.split(",");
for(var i = 0; i < cdata.length; i++)
cdata[i] = parseInt(cdata[i], 10);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With