获取数组中某个指定的元素位置。
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var a = fruits.indexOf("Apple");
输出2
常用来判断是否在数组中
var fruits = ["Banana", "Orange", "Apple", "Mango"];
if(fruits .indexOf("Banana") !== -1){
console.log("在数组里")
}
获取数组中某个指定的元素位置。
var fruits = ["Banana", "Orange", "Apple", "Mango"];
var a = fruits.indexOf("Apple");
输出2
常用来判断是否在数组中
var fruits = ["Banana", "Orange", "Apple", "Mango"];
if(fruits .indexOf("Banana") !== -1){
console.log("在数组里")
}
本文标题:indexOf
本文链接:https://www.haomeiwen.com/subject/choynctx.html
网友评论