Created
June 9, 2022 12:03
-
-
Save sktwentysix/e731f448feacca12b4cc72250cda3f52 to your computer and use it in GitHub Desktop.
A simple array reducer example using objects
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
const array = [ | |
{ id: 111, framework: 'react' }, | |
{ id: 222, framework: 'angular' }, | |
{ id: 333, framework: 'vue' } | |
]; | |
const reducerCallback = (prevItem, currItem) => { | |
return { | |
id: prevItem.id + currItem.id, | |
framework: prevItem.framework + "-" + currItem.framework | |
} | |
} | |
console.log(array.reduce(reducerCallback)) // returns `{ id: 666, framework: 'react-angular-vue' }` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment