簡體   English   中英

使用 JavaScript 轉換 CSV 文件中的數組數組

[英]Convert array of array in CSV file using JavaScript

我有一個包含兩個對象的數組,可以說:

one=[{ "apple":1, "ball":2},{"apple":2,"ball":5}]

我還有另一個對象:

two=[{"cat":2}];

我期待着:

two=[{"apple":"1,2", "ball":"2,5", "cat":2}]

我怎樣才能做到這一點?

提前致謝。

嘗試這個:

 var one=[{ "apple":1, "ball":2},{"apple":2,"ball":5}]; var two=[{"cat":2}]; two = two.concat(one); var res = {}; for(let ind = 0 ; ind<two.length;ind++) { for(let [key,value] of Object.entries(two[ind])) { if(res[key] == undefined) { res[key] = []; } res[key].push(value); } } console.log(res);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM