How to split a nested array into a new array

list:[
0:Array(n)
old:[
    0:{id: 31, productName: "Old123", stockPrice: 20, }
    1:{id: 32, productName: "Old123", stockPrice: 10, }
    ...
 ],
new:[
    0:{id: 33, productName: "new123", stockPrice: 20, }
    1:{id: 34, productName: "new123", stockPrice: 10, }
    ...
 ],
1:Array(n)
old:[
    0:{id: 35, productName: "Old123", stockPrice: 20, }
    1:{id: 36, productName: "Old123", stockPrice: 10, }
    ...
 ],
new:[
    0:{id: 37, productName: "new123", stockPrice: 20, }
    1:{id: 38, productName: "new123", stockPrice: 10, }
    ...
 ],
 ...
]

there is a nested array. I"m going to push the contents of old to a new array oldlist how to push the contents of new to newlist

oldlist:[
    0:[
        0:{id: 31, productName: "Old123", stockPrice: 20, }
        1:{id: 32, productName: "Old123", stockPrice: 10, }
        ...
    ],
    1:[
        0:{id: 35, productName: "Old123", stockPrice: 20, }
        1:{id: 36, productName: "Old123", stockPrice: 10, }
        ...
    ],
    ...
]
newList:[
    0:[
        0:{id: 33, productName: "new123", stockPrice: 20, }
        1:{id: 34, productName: "new123", stockPrice: 10, }
        ...
    ],
    1:[
        0:{id: 37, productName: "new123", stockPrice: 20, }
        1:{id: 38, productName: "new123", stockPrice: 10, }
        ...
    ],
    ...
]

I traverse list, then traverse old and new, respectively, and push to get an array like this

oldlist:[
    0:{id: 31, productName: "Old123", stockPrice: 20, }
    1:{id: 32, productName: "Old123", stockPrice: 10, }
    2:{id: 35, productName: "Old123", stockPrice: 20, }
    3:{id: 36, productName: "Old123", stockPrice: 10, }
    ...
]

the ps: system requires you to modify the content of the picture and find a new problem by changing it-- |

Nov.10,2021

list2.push(...item.arr1.map(_item => ({name1: _item.name, id1: _item.id})))
Menu