JS 怎么将如下两组数组,拼接如下格式?
将newKey数组和newValList数组,拼接如下格式:
data: [{ `spData: [{key: '颜色', value: '白色'}, {key: '重量', value: '25KG'}, {key:'测试类型', value:'测试1'}]`
},
{
spData: `[{key: '颜色', value: '黑色'},{key: '重量', value: '25KG'},{key:'测试类型', value:'测试1'}]`
}]
回答:
let newKey = [{key: '颜色'}, {key: '重量'}, {key: '测试类型'}]let newValList = [
['黑色', '25KG', '测试'],
['白色', '25KG', '测试']
]
let list = newValList.map(list => {
return {
spData: newKey.map((item, index) => ({...item, value: list[index]}))
}
})
console.log(list)
回答:
用 map
就可以了
spData.map(el => el.value)
以上是 JS 怎么将如下两组数组,拼接如下格式? 的全部内容, 来源链接: utcz.com/p/933430.html