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 1 year has passed since last update.

【JavaScript】配列から条件に一致する要素を取得する方法

Posted at

findメソッド

findは、配列から条件に一致した最初の要素を返します。
一致するものがない場合にはundefindを返します。

const numbers = [1, 2, 3, 4, 5]

const found = numbers.find((number) => number > 2)

console.log(found) // 3

filterメソッド

filterは配列から条件に一致した全ての要素を配列で返します。
一致する要素がない場合には空の配列を返します。

const numbers = [1, 2, 3, 4, 5]

const result = numbers.filter((number) => number > 2)

console.log(result) // [3, 4, 5]

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?