JavaScript根據(jù)對(duì)象的某個(gè)屬性獲得其在數(shù)組中的索引值
let arr = [{id:123,name:"apple"},{id:456,name:"watermelon"}]
let index = arr.findIndex( item => item.name == "watermelon")
console.log(index) // 1
JavaScript根據(jù)對(duì)象的某個(gè)屬性獲得其在數(shù)組中的索引值
let arr = [{id:123,name:"apple"},{id:456,name:"watermelon"}]
let index = arr.findIndex( item => item.name == "watermelon")
console.log(index) // 1