js数组的索引为何不能用负数

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' ]

 

posted @ 2021-04-15 22:31  天渺工作室  阅读(378)  评论(0编辑  收藏  举报