[JavaScript]Array.find()で配列内の最初の要素を返すサンプル

説明
find() メソッドは、提供されたテスト関数を満たす配列内の 最初の要素 の 値 を返します。
使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const arr = [5, 2, 18, 130, 44];
const res = arr.find(element => element > 15);
console.log("配列内の最初の要素")
console.log(res);
const arr = [5, 2, 18, 130, 44]; const res = arr.find(element => element > 15); console.log("配列内の最初の要素") console.log(res);
const arr = [5, 2, 18, 130, 44];

const res = arr.find(element => element > 15);

console.log("配列内の最初の要素")
console.log(res);

結果
> 18

JavaScript

Posted by arkgame