类数组对象

类数组对象没有多大用处,完全可以使用数组类型替代。

类数组对象 - 图1
image.png

自定义类数组对象

  1. const a = {
  2. 0: 'a',
  3. 1: 'b',
  4. 2: 'c',
  5. 3: 'd',
  6. name'chen',
  7. age: 23,
  8. length: 4//注意length属性值
  9. 'push': Array.prototype.push, //添加一个push方法
  10. 'splice': Array.prototype.splice
  11. }
  12. a.push('e');
  13. Array.prototype.unshift.call(a, 'f'); //可以使用回调数组方法
  14. console.log(a);

image.png

参考

https://www.cnblogs.com/oklfx/p/8127473.html