Last active
April 23, 2019 16:33
-
-
Save syeo66/a57653e1d0c5f49b6a8452d35ca1badc to your computer and use it in GitHub Desktop.
Using .map() to mutate object properties
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
const objects = [ | |
{id: 10, name: "Doe", firstname: "John", slug: "john"}, | |
{id: 20, name: "Doe", firstname: "Jane", slug: "jane"}, | |
{id: 30, name: "Mitchell", firstname: "John", slug: "john"}, | |
{id: 40, name: "Money", firstname: "Boy", slug: "boy"} | |
]; | |
const result = objects.map(obj => { | |
obj.slug = `${obj.firstname}-${obj.name}`.toLowerCase() | |
return obj; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment