Skip to content

Instantly share code, notes, and snippets.

@syeo66
Last active April 23, 2019 16:33
Show Gist options
  • Save syeo66/a57653e1d0c5f49b6a8452d35ca1badc to your computer and use it in GitHub Desktop.
Save syeo66/a57653e1d0c5f49b6a8452d35ca1badc to your computer and use it in GitHub Desktop.
Using .map() to mutate object properties
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