Quantcast
Channel: How do I check if an array includes a value in JavaScript? - Stack Overflow
Viewing all articles
Browse latest Browse all 66

Answer by Neil Girardi for How do I check if an array includes a value in JavaScript?

$
0
0

If you're working with ES6 You can use a set:

function arrayHas( array, element ) {
    const s = new Set(array);
    return s.has(element)
}

This should be more performant than just about any other method


Viewing all articles
Browse latest Browse all 66

Trending Articles