Created
August 31, 2020 14:01
-
-
Save AitorAlejandro/1f42bbbd6db4e5011b0ec70be9ab71ed to your computer and use it in GitHub Desktop.
Add a new property to every object in a list
This file contains hidden or 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
| 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