findIndex()
方法返回數組中滿足提供的測試函數的第一個元素的索引。若沒有找到對應元素則返回-1。
值類型:
const array1 = [5, 12, 8, 130, 44];
const isLargeNumber = (element) => element == 12;
console.log(array1.findIndex(isLargeNumber));
數組對象: var index = DiaryNoList.findIndex((value) => value.diaryno == this.info.diaryno);
find()
const array1 = [5, 12, 8, 130, 44];
const found = array1.find(element => element > 10);
console.log(found);
// expected output: 12