使用 indexOf 与 filter
let data = [{
id:1,
name:"小红"
},{
id:2,
name:"小明"
}];
data.indexOf(data.filter(d=>d.id == 1)[0]) //index:0
data.indexOf(data.filter(d=>d.id == 2)[0]) //index:1
data.indexOf(data.filter(d=>d.name == "小红")[0]) //index:0
data.indexOf(data.filter(d=>d.name == "小明")[0]) //index:1
data.indexOf(data.filter(d=>d.id == 3)[0]) // 不存在即返回-1