w3shcool里对于 slice() 方法的描述貌似不对

http://www.w3school.com.cn/jsref/jsref_slice_array.asp

end 可选。规定从何处结束选取。该参数是数组片断结束处的数组下标。

var arr = new Array(6)

arr[0] = "George"

arr[1] = "John"

arr[2] = "Thomas"

arr[3] = "James"

arr[4] = "Adrew"

arr[5] = "Martin"


console.log(arr) 

    //["George", "John", "Thomas", "James", "Adrew", "Martin"] 

console.log(arr.slice(2,4))

    //["Thomas", "James"]  James是第四个,但下标是3

console.log(arr)

    //["George", "John", "Thomas", "James", "Adrew", "Martin"] 

当然,还有一种理解就是 2 <= x < 4

不知道我的理解对不对,还是钻牛角了


holdtom
浏览 446回答 0
0回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript