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のincludesメソッド

Posted at

特定の要素が配列に含まれているかどうかを true または false で返すメゾッド。

配列名.includes( 配列内にあるか確認したい数字や文字列 )

const array1 = [1, 2, 3];
console.log(array1.includes(2));
// => true
// 第2引数以降の数字に含まれていない第1引数の配列を返す

const without = (array, ...numbers) => {
  const withoutNumber = []
  for (let i = 0; i < array.length; i++) {
    const filterNumber = array[i]
    if (!numbers.includes(filterNumber)) {
      withoutNumber.push(filterNumber)
    }
  }
  return withoutNumber
}

console.log(without([2, 1, 2, 3, 4], 1, 2))
// => [3, 4]
0
0
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
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?