πΌ This rule is enabled in the following configs: β
recommended, βοΈ unopinionated.
π§π‘ This rule is automatically fixable by the --fix CLI option and manually fixable by editor suggestions.
Set#has() is faster than Array#includes().
// β
const array = [1, 2, 3];
const hasValue = value => array.includes(value);
// β
const set = new Set([1, 2, 3]);
const hasValue = value => set.has(value);// β
// This array is not only checking existence.
const array = [1, 2];
const hasValue = value => array.includes(value);
array.push(3);// β
// This array is only checked once.
const array = [1, 2, 3];
const hasOne = array.includes(1);