存在则返回 >-1 的数值,即索引位置
# 字符串类型判断是否存在
testdata = "1"
let testString = ["1", "2", "3", "4", "5", "6"];
if(test.indexOf(testdata) != -1){
console.log("字符串数组 testString 内存在字符串 "1" ")
}
# 数字类型判断是否存在
testindex = 3
let testIndex = [1, 2, 3, 4, 5, 6];
if(test.indexOf(testindex) != -1){
console.log("数字数组 testIndex 内存在数字 1")
}