Skip to content

Instantly share code, notes, and snippets.

@AitorAlejandro
Created August 31, 2020 14:01
Show Gist options
  • Save AitorAlejandro/1f42bbbd6db4e5011b0ec70be9ab71ed to your computer and use it in GitHub Desktop.
Save AitorAlejandro/1f42bbbd6db4e5011b0ec70be9ab71ed to your computer and use it in GitHub Desktop.
Add a new property to every object in a list
function addProperty(objList, newProperty) {
return objList.map((obj) => ({
...obj,
...newProperty,
}));
}
// use case
const sectionList = [
{
title: 'title 1',
text: 'text 1'
},
{
title: 'title 1',
text: 'text 1'
}
];
addProperty(sectionList, {expanded: false});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment