我有一张 table
const header = ["name", "age", "hobby"];
const content = [ ["Eva", 3, "dance"],
["Kevin", 5, "ball"],
...];
如何获得对象数组形式的输出?
[{name: "Eva", age: 3, hobby: "dance"},
{name: "Kevin", age: 5, hobby: "ball"},
...]
最佳答案
Lodash
(或underscore.js
)库提供了一些很好的函数来转换数据。只有一行:
import _ from 'lodash';
const output = content.map((row) => _.zipObject(row, header));
关于javascript - 在 JavaScript 中将表转换为对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51490096/