mardi 4 août 2015

java script how to convert a string to number array

I have a string named :

graph_data =[16.665,0,16.665,19.23,35.79,16.665,31.71,16.665,0,16.665,0,16.665,16.665,41.615]

I wanted to covert it to array of number. I am using the following code:

var graph_data1=new Array();
var graph_data = graph_data.split(",");
for (var i=0; i<graph_data.length; i++)
{
graph_data1[i] = parseFloat(graph_data[i]);
}

the output of graph_data1 is showing following NaN,0,16.665,19.23,35.79,16.665,31.71,16.665,0,16.665,0,16.665,16.665,41.615

can any one tell me why it is adding Nan and 0

thanks in advance .

Aucun commentaire:

Enregistrer un commentaire