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

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

More than 5 years have passed since last update.

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]

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

kozo002
mof-mof
「つくって人をしあわせにする」をビジョンにAIチャットボットや開発チームレンタル等のサービスを提供している渋谷のIT企業です
https://www.mof-mof.co.jp/about
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