JavaScript根据对象的某个属性获得其在数组中的索引值
let arr = [{id:123,name:"apple"},{id:456,name:"watermelon"}]
let index = arr.findIndex( item => item.name == "watermelon")
console.log(index) // 1
JavaScript根据对象的某个属性获得其在数组中的索引值
let arr = [{id:123,name:"apple"},{id:456,name:"watermelon"}]
let index = arr.findIndex( item => item.name == "watermelon")
console.log(index) // 1