Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #array #object #javascript #spread
ADD COMMENT
Topic
Name
2+5 =