includes
let aa = [1,2,3,4,5,6,7,8,9]
// let ss = aa.includes(1)
let ss = aa.includes(10)
console.log(ss)
let aa = [1,2]
let dd = [{id:1, name: 'aaa'}, {id: 2, name: 'bbb'}, {id:3, name: 'cccc'}, {id:4, name: 'dddd'}]
dd.forEach(item=>{
if(aa.includes(item.id)){
item.disabled = true
}else{
item.disabled = false
}
})
console.log(dd)
indexOf
let aa = [3,4]
let dd = [{id:1, name: 'aaa'}, {id: 2, name: 'bbb'}, {id:3, name: 'cccc'}, {id:4, name: 'dddd'}]
dd.forEach(item=>{
if(aa.indexOf(item.id) != -1){
item.disabled = true
}else{
item.disabled = false
}
})
console.log(dd)
setTimeout(()=>{
aa.push(1)
dd.forEach(item=>{
if(aa.indexOf(item.id) != -1){
item.disabled = true
}else{
item.disabled = false
}
})
console.log(dd)
},2000)
网友评论