getRepeatId (arr, id) {
var index = arr.findIndex(item => item.id=== id)
return index // -1 说明arr中不存在id为传入id的对象
}
const arr = [{id: 1},{id: 2},{id: 3},{id: 4},{id: 5}]
this.getRepeatId(arr, 1)
this.getRepeatId(arr, 6)
getRepeatId (arr, id) {
var index = arr.findIndex(item => item.id=== id)
return index // -1 说明arr中不存在id为传入id的对象
}
const arr = [{id: 1},{id: 2},{id: 3},{id: 4},{id: 5}]
this.getRepeatId(arr, 1)
this.getRepeatId(arr, 6)
本文标题:判断数组中是否包含某个id的对象
本文链接:https://www.haomeiwen.com/subject/wsogddtx.html
网友评论