findLastIndex Method
findLastIndex method သည်
parameter အဖြစ်ပေးလိုက်သော callback function နှင့်အညီ
အခြေအနေနှင့်ကိုက်ညီသော array ၏အဆုံးမှ ပထမဆုံး element ၏
index ကိုရှာဖွေရန် အကူအညီပေးပါသည်။
element မရှိပါက
-1 ကို ပြန်ပေးပါသည်။
Syntax
array.findLastIndex(function);
ဥပမာ
Array ထဲတွင် ဂဏန်းအပေါင်းတစ်ခု၏ index ကို ရှာကြည့်ရအောင်။
let arr = [-12, -13, 14, 15];
let res = arr.findLastIndex(function(elem) {
return elem > 0;
});
console.log(res);
Code run ပြီးရရှိလာသော ရလဒ်။
3
ဥပမာ
ယခု array ထဲတွင် မရှိသော element တစ်ခု၏ index ကို ရှာကြည့်ရအောင်။
let arr = ['a', 'b', 'c', 'd'];
let res = arr.findLastIndex(function(elem) {
return elem === 'f';
});
console.log(res);
Code run ပြီးရရှိလာသော ရလဒ်။
-1