Last active
January 18, 2024 09:57
-
-
Save andrejsharapov/24d75bc2bfc42a3acd443ed7efa52bba to your computer and use it in GitHub Desktop.
[ js]: внутри одного массива объединить объекты с общим значением в подмассивы
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 array = []; | |
// inside one array, combine objects with a common value into sub arrays js | |
const arr = Object.values( | |
array.reduce((r, cur) => { | |
const key = 'k' + cur['code_importance_event']; | |
(r[key] = r[key] || []).push(cur); | |
return r; | |
}, {}) | |
); | |
return arr; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment