Array.prototype.includes()

This translation is incomplete.Please help translate this article from English

砖讬讟转 includes() 拽讜讘注转 讗诐 诪注专讱 诪讻讬诇 讗诇诪谞讟 诪住讜讬讬诐, 诪讞讝讬专 true 讗讜 false 讘讛转讗诐.

转讞讘讬专

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

驻专诪讟专讬诐

searchElement
讛讗诇诪谞讟 讗讜转讜 诪讞驻砖讬诐
fromIndex
讗讜驻爪讬讜谞诇讬. 讛诪讬拽讜诐 讘诪注专讱 讘讜 诇讛转讞讬诇 讗转 讛讞讬驻讜砖 讗讞专 searchElement. 注专讱 砖诇讬诇讬 讬转讞讬诇 讗转 讛讞讬驻讜砖 诪讛注专讱 讛讗讞专讜谉 (array.length) + fromIndex 讘住讚专 注讜诇讛. 讘专讬专转 诪讞讚诇 0.

注专讱 诪讜讞讝专 (Return)

Boolean.

讚讜讙诪讗讜转

[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 Latest Draft (ECMA-262)
The definition of 'Array.prototype.includes' in that specification.
Draft

转讗讬诪讜转 讚驻讚驻谞讬诐

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

专讗讛 注讜讚