猿问

为何不输出6个true?

function bouncer(arr) {

  rule=[false,null,0,"",undefined,NaN];

  changed=[];

  for (i=0;i<arr.length;i++){

    dis=false;

    for(j=0;j<6;j++){

      if(arr[i]===rule[j]){dis=true;}

      break;

    }

    console.log(dis);

  }

}


bouncer([false, null, 0, NaN, undefined, ""]);

为何不输出6个true?

翻阅古今
浏览 504回答 1
1回答

炎炎设计

function bouncer(arr) {&nbsp; rule=[false,null,0,"",undefined,NaN];&nbsp; changed=[];&nbsp; for (i=0;i<arr.length;i++){&nbsp; &nbsp; dis=false;&nbsp; &nbsp; for(j=0;j<6;j++){&nbsp; &nbsp; &nbsp; if(arr[i]===rule[j]){&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; dis=true;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; break;&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; }&nbsp; &nbsp; console.log(dis);&nbsp; }}仔细看你代码中break的位置。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答