JavaScript - Arrays - includes

javascript-arrays

// Array.prototype.includes()
arr.includes(searchElement)
arr.includes(searchElement, fromIndex)

The includes() method determines whether an array includes a certain element, 
returning true or false as appropriate.

searchElement: The element to search for.
fromIndex: Optional.  The position in this array at which to begin searching for 
  searchElement. A negative value searches from the index of array.length + 
  fromIndex by asc. Defaults to 0.

[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
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License