Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 668 Bytes

prefer-set-has.md

File metadata and controls

35 lines (24 loc) · 668 Bytes

Prefer Set#has() over Array#includes() when checking for existence or non-existence

Set#has() is faster than Array#includes().

This rule is fixable.

Fail

const array = [1, 2, 3];

function isExists(find) {
	return array.includes(find);
}

Pass

const set = new Set([1, 2, 3]);

function isExists(find) {
	return set.has(find);
}
const array = [1, 2];

function isExists(find) {
	return array.includes(find);
}

array.push(3);