数组对象中key值为数组的数据处理成多个对应的数组对象
准备数据
let list = [{
"name": "a",
"age": 11,
"id": [1]
}, {
"name": "b",
"age": 22,
"id": [2, 5]
}, {
"name": "c",
"age": 33,
"id": [3]
}, {
"name": "name",
"age": 44,
"id": [67]
}, {
"name": "d",
"age": 55,
"id": [5, 6]
}]
结果
[{"name":"a","age":11,"id":1},{"name":"b","age":22,"id":5},{"name":"c","age":33,"id":3},{"name":"name","age":44,"id":67},{"name":"d","age":55,"id":6}]
let newList = arr2.map(({...item}) => {
item.id.map(o => {
item.name = item.name,
item.id = o
})
return item
})
console.log(newList);