Array.prototype.includes()

ืฉื™ื˜ืช includes() ืงื•ื‘ืขืช ืื ืžืขืจืš ืžื›ื™ืœ ืืœืžื ื˜ ืžืกื•ื™ื™ื, ืžื—ื–ื™ืจ true ืื• false ื‘ื”ืชืื.
 

ืชื—ื‘ื™ืจ

var boolean = array.includes(searchElement[, fromIndex])

ืคืจืžื˜ืจื™ื

searchElement
ื”ืืœืžื ื˜ ืื•ืชื• ืžื—ืคืฉื™ื
fromIndex
ืื•ืคืฆื™ื•ื ืœื™. ื”ืžื™ืงื•ื ื‘ืžืขืจืš ื‘ื• ืœื”ืชื—ื™ืœ ืืช ื”ื—ื™ืคื•ืฉ ืื—ืจ searchElement. ืขืจืš ืฉืœื™ืœื™ ื™ืชื—ื™ืœ ืืช ื”ื—ื™ืคื•ืฉ ืžื”ืขืจืš ื”ืื—ืจื•ืŸ (array.length) + fromIndex ื‘ืกื“ืจ ืขื•ืœื”. ื‘ืจื™ืจืช ืžื—ื“ืœ 0.

ืขืจืš ืžื•ื—ื–ืจ (Return)

ื“ื•ื’ืžืื•ืช

[1, 2, 3].includes(2);     // true
[1, 2, 3].includes(4);     // false
[1, 2, 3].includes(3, 3);  // false
[1, 2, 3].includes(3, -1); // true
[1, 2, NaN].includes(NaN); // true

ืคื•ืœื™ืคื™ืœ - Polyfill

if (!Array.prototype.includes) {
  Array.prototype.includes = function(searchElement /*, fromIndex*/) {
    'use strict';
    if (this == null) {
      throw new TypeError('Array.prototype.includes called on null or undefined');
    }

    var O = Object(this);
    var len = parseInt(O.length, 10) || 0;
    if (len === 0) {
      return false;
    }
    var n = parseInt(arguments[1], 10) || 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)) { // NaN !== NaN
        return true;
      }
      k++;
    }
    return false;
  };
}

ืžืคืจื˜

ืžืคืจื˜ ืกื˜ื˜ื•ืก ื”ืขืจื”
ECMAScript 2016 (ECMA-262)
The definition of 'Array.prototype.includes' in that specification.
Standard ื”ื’ื“ืจื” ืจืืฉื•ื ื™ืช
ECMAScript (ECMA-262)
The definition of 'Array.prototype.includes' in that specification.
Living Standard  

ืชืื™ืžื•ืช ื“ืคื“ืคื ื™ื

We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains. Find out how you can help!
ืžืืคื™ื™ืŸ Chrome Firefox (Gecko) Internet Explorer Edge Opera Safari
ืชืžื™ื›ื” ื‘ืกื™ืกื™ืช

47

43 No support 14279+ 34 9
ืžืืคื™ื™ืŸ Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
ืชืžื™ื›ื” ื‘ืกื™ืกื™ืช No support

47

43 No support 34 9

47

ืจืื” ืขื•ื“