Help us understand the problem. What is going on with this article?

lodash でよく使う王道関数

More than 1 year has passed since last update.

JavaScript を使っているなら lodash は大変便利なのですが、関数が多すぎてどれ使ったらいいのか解りづらいのが難点です。

ここではその中から特によく使う関数を紹介します。

_.chunk(array, [size=1]) : 配列を指定サイズで分割

// 配列を指定サイズで分割
_.chunk(['a', 'b', 'c', 'd'], 2);
// => [['a', 'b'], ['c', 'd']]

_.difference(array, [values]) : 差集合。つまり左から右を除去。

_.difference([2, 1], [2, 3]);
// => [1]

_.intersection([arrays]) : 積集合。つまり全てに共通してあるもののみ。

_.intersection([2, 1], [2, 3]);
// => [2]

_.union([arrays]) : 和集合。つまり全ての合算(重複なし)。

_.union([2, 1], [2, 3]);
// => [2, 1, 3]

_.xor([arrays]) : 排他的論理和。つまり全ての中で重複の無い値のみ。

_.xor([2, 1], [2, 3]);
// => [1, 3]

_.fill(array, value, [start=0], [end=array.length]) : 配列を値で埋める。

var array = [1, 2, 3];
_.fill(array, 'a');
console.log(array);
// => ['a', 'a', 'a']

_.uniq(array) : 重複排除。

_.uniq([2, 1, 2]);
// => [2, 1]

_.isEnpty(value) : 空判定。

_.empty({});
// => true
_.empty({a: 1});
// => false

lodash関連の記事

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした