[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Array/includes [Back]  [Original]

Array.prototype.includes() - JavaScript | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Array.prototype.includes()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2016 8.

Array includes() true false .

In this article

const array1 = [1, 2, 3];

console.log(array1.includes(2));
// Expected output: true

const pets = ["cat", "dog", "bat"];

console.log(pets.includes("cat"));
// Expected output: true

console.log(pets.includes("at"));
// Expected output: false

js
includes(searchElement)
includes(searchElement, fromIndex)

searchElement

.

fromIndex Optional

0 , .

  • . , fromIndex < 0, fromIndex + array.length . , .
  • fromIndex < -array.length fromIndex , 0 .
  • fromIndex >= array.length , false .

( fromIndex , fromIndex ) searchElement true .

includes() SameValueZero searchElement . 0 . (, -0 0 ), false 0 . NaN .

, include() undefined .

includes() . this length .

includes()

js
[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
["1", "2", "3"].includes(3); // false

fromIndex

fromIndex false . .

js
const arr = ["a", "b", "c"];

arr.includes("c", 3); // false
arr.includes("c", 100); // false

0

fromIndex , searchElement . 0 .

js
//   3
// fromIndex -100
//   3 + (-100) = -97

const arr = ["a", "b", "c"];

arr.includes("a", -100); // true
arr.includes("b", -100); // true
arr.includes("c", -100); // true
arr.includes("a", -2); // false

includes()

undefined true .

js
console.log([1, , 3].includes(undefined)); // true

includes()

includes() this length length .

js
const arrayLike = {
  length: 3,
  0: 2,
  1: 3,
  2: 4,
  3: 1, // length 3 includes() .
};
console.log(Array.prototype.includes.call(arrayLike, 2));
// true
console.log(Array.prototype.includes.call(arrayLike, 1));
// false

Specification
ECMAScript 2027 LanguageSpecification
# sec-array.prototype.includes


Web Proxy Viewer  |  New URL  |  Original Page