ECMAScript 7 introduces Array.prototype.includes.
It can be used like this:
[1, 2, 3].includes(2); // true
[1, 2, 3].includes(4); // false
It also accepts an optional second argument fromIndex:
[1, 2, 3].includes(3, 3); // false
[1, 2, 3].includes(3, -1); // true
Unlike indexOf, which uses Strict Equality ComparisonStrict Equality Comparison, includes compares using SameValueZeroSameValueZero equality algorithm. That means that you can detect if an array includes a NaN:
[1, 2, NaN].includes(NaN); // true
Also unlike indexOf, includes does not skip missing indices:
new Array(5).includes(undefined); // true
Currently it's still a draft butIt can be polyfilledpolyfilled to make it work on all browsers.