LoginSignup
0
1

More than 5 years have passed since last update.

lodashのfirst, last が take, takeRight にそれぞれ機能分割されてた

Last updated at Posted at 2015-02-06

lodashで配列を扱う関数で firstlast というのがあって、通常は配列の先頭を取り出すのが first、末尾を取り出すのが last なんだけど、2番目の引数にnumberを渡すとその長さ分を先頭または末尾から取り出してくれてた。

var numbers = [1, 2, 3]
console.log(_.first(numbers)) // => 1
console.log(_.first(numbers, 2)) // => [1, 2]
console.log(_.last(numbers)) // => 3
console.log(_.last(numbers, 2)) // => [2, 3]

というのはもう過去の話!

今はこうやる

var numbers = [1, 2, 3]
console.log(_.take(numbers, 2)) // => [1, 2]
console.log(_.takeRight(numbers, 2)) // => [2, 3]

わかりやすい名前になってた

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