简体   繁体   中英

combine (join) objects in array javascript

In d3.csv("file.csv", function(error, data) instruction

d3.csv is a helper that uses d3.csv.parse internally to parse CSV data loaded from a file into an array of objects, and then it passes this to a callback.

So data is a callback variable that holds an array of objects

In the picture the structure of data数据

You can see that the headers of the original CSV have been used as the property names for the data objects .Using d3.csv in this manner requires that your CSV file has a header row.

data is array of objects

data (in orange) is a combination of :
- columns array (in red) holding csv headers that means **property names** 
  for the **data objects**
- an array of 6131 elements (in green) holding the values associated with 
  these propertie

Now that we have finished describing the desired structure:

Imagine I have an array of 6131 elements (the same as described in the picture in green)

var dataArray =[];
 for(var i=0;i<6131;i++){
        ddd[i]={x:..,y:...etc};
        dataArray.push(ddd[i]); 
 }

My question is how to construct in reverse the same identical structure described before and result with the same data like the one got from d3.csv.

var columnsArray=["NOM","PRENOM","SPECIALITE","Full_Address","VILLE","lat","lon"];

Thank you very much for help.

您可以将columns属性附加到您的dataArray对象:

dataArray.columns = columnsArray;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM