check if an array has a value in JavaScript?

Array.prototype.includes()

The includes() method determines whether an array includes a certain value among its entries

 

console.log([43534,453466,4354654].includes(4354654))

 

While indexof method returns index of value if exists in array otherwise it return -1

console.log([43534,453466,4354654].indexOf(43544654))

 

Thanks :)


Tags:

Share:

Related posts