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 Aurobindo Bhuyan for How do I check if an array includes a value in JavaScript?

$
0
0

There are several ways to find out.You can use inbuilt Array methods. The most prominently used is Array find method.

const arr1 = [1, 2, 3, 4, 5]const result = arr1.find(ele => ele === 4)console.log(result) //4const result2 = arr1.find(ele => ele === 6)console.log(result2) //undefined/* If the element is present inside the arraythen it will return the first element thatsatisfies the given condition. Otherwiseundefined will return.*/

Viewing all articles
Browse latest Browse all 66

Latest Images

Trending Articles





Latest Images