Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

check if an element is there in js

//includes
const fruits = ["apple", "mango", "banana", "kiwi"]
return fruits.includes("mango") ? true : false; //returns true if element is in the array

//find Index
let matchIndex = fruits.findIndex((fruit)=>{return fruit == "mango"});
matchIndex > -1 ? fruits[matchIndex] : null;
//other than -1 means the element is in the array.
 
PREVIOUS NEXT
Tagged: #check #element #js
ADD COMMENT
Topic
Name
7+6 =