弗雷奇。如何打破?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了弗雷奇。如何打破?相关的知识,希望对你有一定的参考价值。

Array.prototype.forEach
You can't break forEach. So use "some" or "every".
Array.prototype.some
some is pretty much the same as forEach but it break when the callback returns true.
Array.prototype.every
every is almost identical to some except it's expecting false to break the loop.
  1. var ary = ["javascript", "Java", "CoffeeScript", "TypeScript"];
  2.  
  3. ary.some(function (value, index, _ary) {
  4. console.log(index + ": " + value);
  5. return value === "CoffeeScript";
  6. });
  7. // output:
  8. // 0: JavaScript
  9. // 1: Java
  10. // 2: CoffeeScript
  11.  
  12. ary.every(function(value, index, _ary) {
  13. console.log(index + ": " + value);
  14. return value.indexOf("Script") > -1;
  15. });
  16. // output:
  17. // 0: JavaScript
  18. // 1: Java

以上是关于弗雷奇。如何打破?的主要内容,如果未能解决你的问题,请参考以下文章