js怎么把对象下的一个数组进行拆分形成两个对象,大佬们求解!!

比如:

{
    id:123,
    name:'zhang',
    order:[
        {
            order_name:'zhang',
            order_on:11002020112123,
            order_create:2020:11:2
        },
        {
            order_name:'li',
            order_on:110020201030123,
            order_create:2020:10:30
        }
    ]
}

拆分成:

{
    id:123,
    name:'zhang',
    order:{
        order_name:'zhang',
        order_on:11002020112123,
        order_create:2020:11:2
    }
},
{
    id:123,
    name:'zhang',
    order:{
        order_name:'li',
        order_on:110020201030123,
        order_create:2020:10:30
    }
}

最佳答案

const obj = 
{
    id:123,
    name:'zhang',
    order:[
        {
            order_name:'zhang',
            order_on:'11002020112123',
            order_create:'2020:11:2'
        },
        {
            order_name:'li',
            order_on:'110020201030123',
            order_create:'2020:10:30'
        }
    ]
};

var newArray = obj.order.map(item => ({
  ...obj,
    order: item
}))

console.log(newArray)