console.log([][-1]); //undefined 并没有报错

排除强类型语言的计算越界现象
JS的Array数组实际是个Object,并不是真的"Array";
t arr = [1,2,3,4]
arr[-1] = 'a'
console.log(arr) //[ 1, 2, 3, 4, '-1': 'a' ]

console.log([][-1]); //undefined 并没有报错
排除强类型语言的计算越界现象
JS的Array数组实际是个Object,并不是真的"Array";
t arr = [1,2,3,4]
arr[-1] = 'a'
console.log(arr) //[ 1, 2, 3, 4, '-1': 'a' ]
本文标题:js数组的索引为何不能用负数
本文链接:https://www.haomeiwen.com/subject/oiajlltx.html
网友评论