![](/img/trans.png)
[英]Merge two arrays with key , and the second array being an object inside the 1st array
[英]Merge two arrays of objects but have the second array pushed into an object key
我希望我的术语在标题上是正确的。
我有一个小提琴我的代码:
https://jsfiddle.net/v3yatpx8/
这给了我不想要的结果。 您可以从 console.log(newArray) 中看到。
我想将 attMap 推送到 prodMap 的“信息”中,并使我的最终数组结构如下:
[ { "info" : [ { "attribute":"Grade:", "value":"Premium OR-Grade" }, { "attribute":"Disposable or Reusable:", "value":"Reusable" }, { "attribute":"Handle:", "value":"Finger Rings" }, ], "name":"Product 1", "sku":"4242" } ]
我真的不知道如何做到这一点。 任何帮助,将不胜感激!
你的 object.assign 语句有点不对劲。
newArray = prodMap.map((itm, i)=> ({
...itm,
info: attMap[i]
}));
映射数组,保留每个 itm,并覆盖其 info 属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.