0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JS 配列の最初以外を返す

Last updated at Posted at 2020-08-02

##Lodashのtail関数を作成してみた
###メソッド使用せずに作成した場合

const tail = (array) => {
  const tailNewArray = []
  for (let i = 1; i < array.length; i++) {
    tailNewArray.push(array[i])
  }
  return tailNewArray
}

console.log(tail([2, 4, 5]))
// => [4, 5]

console.log(tail([1]))
// => []

filterメゾッドを使用した場合

const tail = (numbers = []) => {
  return numbers.filter((value, index, array) => {
    return array.indexOf(value) !== 0
  })
}
console.log(tail([2, 4, 5]))
// => [4, 5]

console.log(tail([1]))
// => []
0
0
1

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?