Answers for "spread syntax add object to arraeyy"

8

add new value to array of object javascript using spread

const newArr = [
  {name: 'eve'},
  {name: 'john'},
  {name: 'jane'}
].map(v => ({...v, isActive: true}))
Posted by: Guest on April-09-2020
0

add new value to array of object javascript using spread

const initialArr = [
      {name: 'eve'},
      {name: 'john'},
      {name: 'jane'}
    ]

const newArr1 = initialArr.map(v => ({...v, isActive: true}))
const newArr2 = initialArr.map(v => Object.assign(v, {isActive: true}))

// Results of newArr1 and newArr2 are the same
Posted by: Guest on April-05-2022

Code answers related to "Javascript"

Browse Popular Code Answers by Language