Add key value pair to all objects in array (ok)

https://stackoverflow.com/questions/39827087/add-key-value-pair-to-all-objects-in-array

I wanted to add a key:value parameter to all the objects in an array.

eg:

var arrOfObj = [{name: 'eve'},{name:'john'},{name:'jane'}];

I wanted to add a key:value parameter to all the objects in an array.

eg:

var arrOfObj = [{name: 'eve'},{name:'john'},{name:'jane'}];

Now I wanted to add a new parameter, isActive to all the objects so the resulting array will look like.

eg:

    [{
    name: 'eve',
    isActive: true
}, {
    name: 'john',
    isActive: true
}, {
    name: 'jane',
    isActive: true
}]
const newArr = [
  {name: 'eve'},
  {name: 'john'},
  {name: 'jane'}
].map(v => ({...v, isActive: true}))

Last updated