📌  相关文章
📜  检查 js 中是否存在元素 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:14.858000             🧑  作者: Mango

代码示例1
//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.