Created
May 9, 2018 23:54
-
-
Save ashwinrs/c054df06e5c5bc33d3ea6142bca35184 to your computer and use it in GitHub Desktop.
Add a new property to an object when creating a new object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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