Skip to content

Instantly share code, notes, and snippets.

@ashwinrs
Created May 9, 2018 23:54
Show Gist options
  • Save ashwinrs/c054df06e5c5bc33d3ea6142bca35184 to your computer and use it in GitHub Desktop.
Save ashwinrs/c054df06e5c5bc33d3ea6142bca35184 to your computer and use it in GitHub Desktop.
Add a new property to an object when creating a new object
/*
arrOfObj = [{"name":"Ash"},{"name":"tim"},{"name":"david"}]
*/
var result = arrOfObj.map(function(el) {
var o = Object.assign({}, el);
o.isActive = true;
return o;
})
console.log(result)
/*
prints:
[{"name":"Ash", "isActive": true},{"name":"tim", "isActive": true},{"name":"david", "isActive": true}]
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment