Best way to find if an item is in a JavaScript array?
var array = [2, 5, 9];
array.indexOf(2); // 0
array.indexOf(7); // -1
let found = array.find(x => x === 5 );
console.log(found); //5
found = array.find(x => x === 51 );
console.log(found); //undefined
What method use to detect value in array ?
array.indexOf(val) !== -1
or
typeof array.find(x => x === val ) !== 'undefined';