code> 的下一个元素 b [] 即可。为此,您需要使用 continue outerloop; 。In this case, if you found a match of the current value from a[], in b[], further checking of that element of a[] would not be necessary. You would want skip the rest, and begin checking the next element of a[] to the elements of b[]. For this, you would want to use "continue outerloop;".outerloop:for(i=0;i<a.length;i++){ for(j=0;j<b.length;j++){ if(b[j] === a[i]){ continue outerloop; } } // if we get to here, then no value // of b[] matched the a[] value, so: // "do something"} 第三种可能性,如果 元素 a [] b [] 中的任何地方找到。为此,您将检查 a [] 的每个元素的值,并将该值与 b [] ,一个接一个,如果在检查 b [] 你找不到与 a [] 当前元素的值匹配,你设置了一个标志并使用 break outerloop; 退出所有循环。然后在最后,如果标志是设置,你可以做某事。A 3rd possibility, is that you want to "do something", only one time, if any element of a[] can't be found anywhere in b[]. For this, you would examine the value of each element of a[], and compare that value to all elements of b[], one by one, and if after checking the value of all elements in b[] you couldn't find a match to the value of the current element of a[], you set a "flag" and exit all the loops using "break outerloop;". Then at the end, if the flag is "set", you can "do something".bflag=false;outerloop:for(i=0;i<a.length;i++){ for(j=0;j<b.length;j++){ if(b[j] === a[i]){ continue outerloop; } } // if we get to here, then no value // of b[] matched the a[] value, so, // set the flag (bflag) bflag=true; break outerloop:}if(bflag){ // "do something"}如果将此代码作为函数调用,可以简化一下:If this code was called as a function, it could be simplified a bit:outerloop:for(i=0;i<a.length;i++){ for(j=0;j<b.length;j++){ if(b[j] === a[i]){ continue outerloop; } } // if we get to here, then no value of b[] matched // the a[] value, so, do-something and return "failed": // "do something" return false;}// all elements of a[] were matched to// elements of b[], so: return "success"return true; 这篇关于JavaScript - 比较两个数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!