javascript - new array from csv data -


i have following csv data:

id,v1,v2,v3,v4,v5 lo,32,45,37,53,22 

i want create new array looks way:

id2,value v1,32 v2,45 v3,37 v4,53 v5,22 

to use following code:

d3.csv("datasbar1.csv", function(error, data) {   if (error) throw error;  var values = d3.keys(data[0]).filter(function(key) {     return key !== "id";});    data.foreach(function(d) {  (var = 0; <= values.length; i++) {     d.value = +d[values[i]];   return d;}});         /*---------- create new array ----------*/  var array = $.map(data, function (d) { for( var i=0; i<=values.length; i++){     return {         id2: values[i],         value: d[values[i]]     }   } });          

it returns me

0: object    id2: "v1"    value: "32" 

and nothing more. doing wrong?

thanks in advance!

don't need many loops below:

d3.csv("my.csv", function(error, data) {   if (error) throw error;    //get values without id       var values = d3.keys(data[0]).filter(function(key) {     return key !== "id";   });   //iterate through values , value using map.   var id2 = values.map(function(id, index) {     return {       "id2": id,       "value": +data[0][id]     };    });   console.log(id2) }); 

working code here


Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -