Javascript Array includes(searchElement /*, fromIndex*/ )

Description

Javascript Array includes(searchElement /*, fromIndex*/ )


Array.prototype.includes = function includes(searchElement /*, fromIndex*/ ) {
'use strict';/* ww  w.j  a  v  a2 s.c om*/
 var O = Object(this);
 var len = parseInt(O.length) || 0;
 if (len === 0) {
  return false;
 }
 var n = parseInt(arguments[1]) || 0;
 var k;
 if (n >= 0) {
  k = n;
 } else {
  k = len + n;
  if (k < 0) {k = 0;}
 }
 var currentElement;
 while (k < len) {
  currentElement = O[k];
  if (searchElement === currentElement ||
     (searchElement !== searchElement && currentElement !== currentElement)) {
   return true;
  }
  k++;
 }
 return false;
};



PreviousNext

Related