0
0

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

Last updated at Posted at 2024-02-05

条件に一致する最初の要素を取得

findを使用して以下のように記述すると条件に一致する最初の要素を取得できます。

const array = [10, 20, 40, 30, 60];
const sampleFind = array.find((element) => element >= 35)
console.log(sampleFind) // 40

条件に一致する要素の配列を取得

filterを使用すると条件に一致する要素の配列を取得できます。

const array = [10, 20, 40, 30, 60];
const sampleFilter = array.filter((element) => element >= 35)

console.log(sampleFilter) // [40, 60]

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