美文网首页
includes和indexOf

includes和indexOf

作者: 偶头像超凶 | 来源:发表于2021-06-09 15:35 被阅读0次

    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)
    

    相关文章

      网友评论

          本文标题:includes和indexOf

          本文链接:https://www.haomeiwen.com/subject/hkpeeltx.html