您的位置:首页 > Web前端

前端开发(一)—— 数组学习

2014-03-13 00:00 239 查看
摘要: 主要针对 Array.length 进行总结

1. Array.length = 数组的最大位数(key)+ 1

var colors = ['red', 'white', 'green']
alert(colors.length) // 3
colors[4] = 'black'
alert(colors.length) // 5
// 现在colors最大位数(key)是4,所以colors.length为5

2. 扩展数组, Array.length可以自定义

var colors = ['red', 'white', 'green']
colors.length = 2
alert(colors[2]) // undefined
colors.length = 3
alert(colors[2]) // undefined
// length自定义为2后,已经删除了colors数组中的green,所以colors[2]为undefined
colors[colors.length] = 'black' // 数组具有扩展性
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  javascript array length