我有这个结构:
materials= ["a","b","c"]
我需要像这样:
data= [{material:"a"},{material:"b"},{material:"c"}]
最佳答案
您可以使用map
:
materials.map(a=> ({material: a}))
一个例子:
let materials= ["a","b","c"];
const result = materials.map(a=> ({material: a}))
console.log(result)
甚至更短(由于Ele):
materials.map(material => ({material}));
let materials= ["a","b","c"];
const result = materials.map(material => ({material}));
console.log(result)