美文网首页
Javascript学习笔记——7.11 类数组对象

Javascript学习笔记——7.11 类数组对象

作者: IFELSE | 来源:发表于2018-06-13 09:14 被阅读0次

数组也是对象,它有其他类型对象没有的特性:

  • 有新的元素添加到数组中时,自动更新length属性;
  • 将length减小将截断数组;
  • 从Array.prototype继承一些有用的方法;
  • 类属性为Array

类数组对象:具有length属性,有非负整数属性(可以通过索引访问),看起来像个数组,可以用数组的方法遍历。

var a ={}
var i = 0
while(i<10){
    a[i] = i*i
    i++
}
a.length = i
var total =0
for(var j=0;j<a.length;j++)
    total+=a[j]
console.log(total)
// 285
Array.isArray(a)
// false

相关文章

网友评论

      本文标题:Javascript学习笔记——7.11 类数组对象

      本文链接:https://www.haomeiwen.com/subject/kywpsftx.html