Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Java by (13.1k points)
Can anyone help me help me what is the best way to find if the object is in an array or not in JavaScript?

1 Answer

0 votes
by (26.7k points)

Basically, you can use includes() function to find:

arr.includes(obj);

Also, for other older browsers, you can try the below code:

function include(arr,obj) {

    return (arr.indexOf(obj) != -1);

}

I hope this will help.

Want to become a Java Expert? join Java Training now!!

Related questions

31k questions

32.9k answers

500 comments

693 users

Browse Categories

...