Skip to content

Instantly share code, notes, and snippets.

@andrejsharapov
Last active January 18, 2024 09:57
Show Gist options
  • Save andrejsharapov/24d75bc2bfc42a3acd443ed7efa52bba to your computer and use it in GitHub Desktop.
Save andrejsharapov/24d75bc2bfc42a3acd443ed7efa52bba to your computer and use it in GitHub Desktop.
[ js]: внутри одного массива объединить объекты с общим значением в подмассивы
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