| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/includes | [Back] [Original] |
Get to know MDN better
const array = [1, 2, 3];
console.log(array.includes(2));
// : true
const pets = ["cat", "dog", "bat"];
console.log(pets.includes("cat"));
// : true
console.log(pets.includes("at"));
// : false
includes(searchElement)
includes(searchElement, fromIndex)
searchElementfromIndex -array.length <= fromIndex < 0 fromIndex + array.length fromIndex < -array.length fromIndex 0 fromIndex >= array.length false searchElement fromIndex true
includes() searchElement SameValueZero -0 0 false 0 NaN
[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 false
const arr = ["a", "b", "c"];
arr.includes("c", 3); // false
arr.includes("c", 100); // false
fromIndex searchElement 0
// 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
undefined true
console.log([1, , 3].includes(undefined)); // true
includes() this length length
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
| ECMAScript 2027 LanguageSpecification # sec-array.prototype.includes |
Arrayat()concat()copyWithin()entries()every()fill()filter()find()findIndex()findLast()findLastIndex()flat()flatMap()forEach()includes()indexOf()join()keys()lastIndexOf()map()pop()push()reduce()reduceRight()reverse()shift()slice()some()sort()splice()toLocaleString()toReversed()toSorted()toSpliced()toString()unshift()values()with()[Symbol.iterator]()Object/Function| Web Proxy Viewer | New URL | Original Page |