check if an element is there in js

Solutions on MaxInterview for check if an element is there in js by the best coders in the world

showing results for - "check if an element is there in js"
Emanuele
23 Jan 2016
1//includes
2const fruits = ["apple", "mango", "banana", "kiwi"]
3return fruits.includes("mango") ? true : false; //returns true if element is in the array
4
5//find Index
6let matchIndex = fruits.findIndex((fruit)=>{return fruit == "mango"});
7matchIndex > -1 ? fruits[matchIndex] : null;
8//other than -1 means the element is in the array.