JavaScript determines whether a string or number exists in a string or number array

If exists, return a value >-1, which is the index position.

# 字符串类型判断是否存在
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")
  }
  

Guess you like

Origin blog.csdn.net/qq_42701659/article/details/132695233