Skip to content

Instantly share code, notes, and snippets.

@WangNingning1994
Created May 23, 2023 05:46
Show Gist options
  • Save WangNingning1994/1e1af4c38c53da7c72f790f130640ef5 to your computer and use it in GitHub Desktop.
Save WangNingning1994/1e1af4c38c53da7c72f790f130640ef5 to your computer and use it in GitHub Desktop.
对象数组的分类方法(依照某个key)
// 对象数组分类方法
const groupBy = (items, key) => items.reduce(
(result, item) => ({
...result,
[item[key]]: [
...(result[item[key]] || []),
item,
],
}),
{},
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment