首页 > 代码库 > js-splice()和js-indexOf()

js-splice()和js-indexOf()

var arr = [‘George‘,‘John‘,‘Thomas‘,‘James‘,‘Adrew‘,‘Martin‘]
console.log(arr)
arr.splice(2,0,"William")//[George,John,William,Thomas,James,Adrew,Martin]
console.log(arr)

return [George,John,William,Thomas,James,Adrew,Martin]


var str="Hello world!"
console.log(str.indexOf("Hello"))//0
console.log(str.indexOf("world"))//6
console.log(str.indexOf("World"))//-1
console.log(str.indexOf("m"))//-1

 

return index(索引)

js-splice()和js-indexOf()