for文で書くと長くなるコードをfindメソッドを使うと簡潔に書ける。
const array1 = [5, 12, 8, 130, 44, 1000];
let result = "";
for (let i = 0; i < array1.length; i++) {
if (array1[i] > 10) {
result = array1[i];
break;
}
}
console.log("result = " + result);
const result2 = array1.find(element => element > 10);
console.log("result2 = " + result2);
/*
result = 12
result2 = 12
*/
Array.prototype.find() – JavaScript | MDN (mozilla.org) ExternalLink