【findIndex】根据数组对象某一元素的id,找到此元素在数组所在的位置
例子:
var listData = [ {id:"1234",name:"bob"}, {id:"2451",name:"mary"}, {id:"6666",name:"tom"}, {id:"5675",name:"jerry"}, {id:"8421",name:"ken"}, ] //找到返回下标 let index = listData.findIndex( item => item.id == '8421'); console.log(index) //4 //找不到返回-1 let index = listData.findIndex( item => item.id == '8888') console.log(index) //-1