for循环中断的问题


  • for循环中使用retun后会直接中断后面的代码执行,类似于map等es6数组方法retun后不会影响,只测试了map,其它未知
  • item.employeeList.map(item=>{
    if(avatorList.length>3) return //////此处中断,依旧会输出111
    if(item.avatar){
    avatorList.push(item.avatar)
    }else{
    avatorList.push('/static/imgs/defaultAvator.png')
    }

    })
    item.avatorList = avatorList
    console.log(111);

  • // for(let i= 0 ;i<item.employeeList.length;i++){
    // if(item.employeeList[i].avatar){
    // avatorList.push(item.employeeList[i].avatar)
    // }else{
    // avatorList.push('/static/imgs/defaultAvator.png')
    // }
    // if(avatorList.length>4) return   ////return之后后面不会执行
    // }
    item.avatorList = avatorList
    console.log(111);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM