2021年4月29日星期四

Spread to create new object for array of object

I've tried to spread my array of object to create a new object but instead destroying the previous object

this is how I tried to spread my array

const currentArraySlug = [    {      slug: "jagung-com", content_viewed: [1, 2], all_viewed: false    }  ]    const newSlug = {    slug: "New slug",    content_viewed: [],    all_viewed: false  }    const mergeData = Object.assign({}, newSlug, ...(currentArraySlug))    console.log(mergeData);

This is my Expected output

{    slug: "jagung-com",    content_viewed: [1, 2],    all_viewed: false  },  {    slug: "New slug",    content_viewed: [],    all_viewed: false  }  

How can I deal with it, Thanks in advance

https://stackoverflow.com/questions/67327315/spread-to-create-new-object-for-array-of-object April 30, 2021 at 10:09AM

没有评论:

发表评论