indexOf()只返回字符串在规定的查找顺序中,首次出现的位置!
var arr = [0,1,'2'];
var str="Hello world!";
console.log("Array",arr.indexOf(1,0)); //1
console.log("string",str.indexOf('d',0)); //10
var arr = [0,1,'2'];
var str="Hello world!";
console.log("Array",arr.indexOf(1)); //1
console.log("string",str.indexOf('s')); //-1
字符串的indexOf在传入参数不是字符串的情况下默认会转换为字符串
var str="Hello 666!";
console.log("string",str.indexOf('6')); //6
console.log("string",str.indexOf(6)); //6
而数组的indexOf不会进行数据类的转换
var arr = [0,1,'2'];
console.log("Array",arr.indexOf(2)); //-1
console.log("Array",arr.indexOf('2')); //2