DEV Community

Discussion on: Why you should use Array.some instead of 'for' loop or forEach?

Collapse
 
luk492 profile image
Luka Kajtes

I totally agree with your comment. Plus this is the polyfill for the "some" implementation. Good old for, just sayin...

if (this == null) {
  throw new TypeError('Array.prototype.some called on null or undefined');
}

if (typeof fun !== 'function') {
  throw new TypeError();
}

var t = Object(this);
var len = t.length >>> 0;

for (var i = 0; i < len; i++) {
  if (i in t && fun.call(thisArg, t[i], i, t)) {
    return true;
  }
}

return false;
Enter fullscreen mode Exit fullscreen mode