LoginSignup
0
1

More than 3 years have passed since last update.

jsで配列の特定keyを指定してgroupByをしたい(lodashすげ〜)

Posted at

jsで配列の特定keyを指定してgroupByをしたい(lodashすげ〜)

結論

lodashすげ〜!!

const array = [
  {id: 1, category: 'ねこ', name: 'ポチ'},
  {id: 1, category: 'ねこ', name: 'ねこねこ'},
  {id: 1, category: 'いぬ', name: 'にゃん'},
];
const key = 'category';

const res = _.groupBy(array, key);

まとめ

lodashはすごいからとりあえずドキュメント読んでおこう!!

Lodash → https://lodash.com/docs/4.17.15
LodashのgroupBy → https://lodash.com/docs/4.17.15#groupBy

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1