infoMore than 3 years have passed since last update.
lodash まとめ (配列編)
Last updated at Posted at 2018-06-24
Array
-
_.chunk(array, [size=1])
: 配列を指定サイズで分割
-
_.compact(array)
: false 的な値除去
-
_.concat(array, [values])
: 配列結合
-
_.difference(array, [values])
: 集合演算。引き算
-
_.differenceBy(array, [values], [iteratee=_.identity])
: 指定の変換(関数やキー名)結果による集合引き算
-
_.differenceWith(array, [values], [comparator])
: 指定の比較関数による集合引き算
-
_.drop(array, [n=1])
: 先頭n個撤去
-
_.dropRight(array, [n=1])
: 末尾n個撤去
-
_.dropRightWhile(array, [predicate=_.identity])
: 末尾から評価成立してる限り撤去
-
_.dropWhile(array, [predicate=_.identity])
: 先頭から評価成立してる限り撤去
-
_.fill(array, value, [start=0], [end=array.length])
: start から end(含まない) まで value で埋める。※array自体書き換わる
-
_.findIndex(array, [predicate=_.identity], [fromIndex=0])
: predicate が true になる最初の index を返す
-
_.findLastIndex(array, [predicate=_.identity], [fromIndex=array.length-1])
: predicate が true になる最後の index を返す
-
_.flatten(array)
: 1段階平たん化
-
_.flattenDeep(array)
: 再帰的に完全に平たん化
-
_.flattenDepth(array, [depth=1])
: 指定段階で平たん化
-
_.fromPairs(pairs)
: [['a', 1], ['b', 2]]
→ { 'a': 1, 'b': 2 }
-
_.head(array)
: 最初の1個
-
_.indexOf(array, value, [fromIndex=0])
: 検索
-
_.initial(array)
: 末尾の要素を撤去 (なんでこの名前?)
-
_.intersection([arrays])
: 集合演算。積集合。
-
_.intersectionBy([arrays], [iteratee=_.identity])
: 指定の変換(関数やキー名)結果による積集合
-
_.intersectionWith([arrays], [comparator])
: 指定の比較関数による積集合
-
_.join(array, [separator=','])
: 既に Array にある
-
_.last(array)
: 最後の要素
-
_.lastIndexOf(array, value, [fromIndex=array.length-1])
: 検索
-
_.nth(array, [n=0])
: 指定番目の値。マイナスも使える
-
_.pull(array, [...values])
: 配列から values の値撤去。※array自体書き換わる
-
_.pullAll(array, values)
: 集合演算。引き算。※array自体書き換わる
-
_.pullAllBy(array, values, [iteratee=_.identity])
:
-
_.pullAllWith(array, values, [comparator])
:
-
_.pullAt(array, [indexes])
: 指定の場所撤去。※array自体書き換わる
-
_.remove(array, [predicate=_.identity])
: 合致するものを撤去。※array自体書き換わる
-
_.sortedIndex(array, value)
: ソート済みであることを前提に2分探索で高速に value が入るべき index を返す
-
_.sortedIndexBy(array, value, [iteratee=_.identity])
: sortedIndex
と同様だが、要素ごとに関数を使う
-
_.sortedIndexOf(array, value)
:
-
_.sortedLastIndex(array, value)
:
-
_.sortedLastIndexBy(array, value, [iteratee=_.identity])
:
-
_.sortedLastIndexOf(array, value)
:
-
_.sortedUniq(array)
: ソートされている配列に最適化された uniq
-
_.sortedUniqBy(array, [iteratee])
:
-
_.tail(array)
: 最初の値以外を返す
-
_.take(array, [n=1])
: 最初からn個を返す
-
_.takeRight(array, [n=1])
:
-
_.takeRightWhile(array, [predicate=_.identity])
:
-
_.takeWhile(array, [predicate=_.identity])
:
-
_.union([arrays])
: 和集合
-
_.unionBy([arrays], [iteratee=_.identity])
:
-
_.unionWith([arrays], [comparator])
:
-
_.uniq(array)
: 重複なくす
-
_.uniqBy(array, [iteratee=_.identity])
:
-
_.uniqWith(array, [comparator])
:
-
_.unzip(array)
: [['a', 'b'], [1, 2], [true, false]]
→ ['a', 'b'], [1, 2], [true, false]
-
_.unzipWith(array, [iteratee=_.identity])
: 要素同士を iteratee で処理する
-
_.without(array, [values])
: 配列から values の値撤去。
-
_.xor([arrays])
: 排他的和集合
-
_.xorBy([arrays], [iteratee=_.identity])
:
-
_.xorWith([arrays], [comparator])
:
-
_.zip([arrays])
:
-
_.zipObject([props=[]], [values=[]])
: fromPair
と同じだが、2つの引数を取る点が異なる
-
_.zipObjectDeep([props=[]], [values=[]])
: プロパティパスを使える。['a.b[0].c', 'a.b[1].d'], [1, 2]
-
_.zipWith([arrays], [iteratee=_.identity])
:
lodash関連の記事
List of users who liked
12Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
What you can do with signing up