😁Array find, Tìm phần tử cuối cùng thỏa mãn điều kiện (ok)
https://stackoverflow.com/questions/40929260/find-last-index-of-element-inside-array-by-certain-condition
var d = [{'a': "something", 'b':12}, {'a': "something", 'b':12}, {'a': "somethingElse", 'b':12}, {'a': "something", 'b':12}, {'a': "somethingElse", 'b':12}]
function findLastIndex(array, searchKey, searchValue) {
var index = array.slice().reverse().findIndex(x => x[searchKey] === searchValue);
var count = array.length - 1
var finalIndex = index >= 0 ? count - index : index;
console.log(finalIndex)
return finalIndex;
}
findLastIndex(d, 'a', 'something')
findLastIndex(d, 'a', 'nothing')
PreviousArray find, Tìm phần tử đầu tiên thỏa mãn điều kiện (ok)NextCách tích hợp bộ lọc select chọn nhanh Tỉnh, Thành & Quận, Huyện, districts, provinces (ok)
Last updated