博客
关于我
js:详解js中的伪数组
阅读量:281 次
发布时间:2019-03-01

本文共 624 字,大约阅读时间需要 2 分钟。

伪数组的特性

如果一个对象的所有键名都是正整数或零,并且有length属性,那么这个对象就很像数组,称为伪数组。典型的伪数组有函数的arguments对象,以及大多数 DOM 元素集,还有字符串。

  • 具有length属性;
  • 按索引方式存储数据;
  • 不具有数组的push()、pop()等方法;

举例

例子1:

  • 1111
  • 1111
  • 1111

获取集合,控制台打印

在这里插入图片描述
例子2:
argumenets 对象
在这里插入图片描述

伪数组转化为真实数组

Array.prototype.slice.call(oUL);

或者 es6 的 Array.from()

Array.from(oUL);

如何实现伪数组和伪数组转化函数

// 一个伪数组var obj = {       "0": "aaa",    "1": 12,    "length": 2,    "push": Array.prototype.push,    "splice": Array.prototype.splice}// 动态改变length,并且添加新元素到数组末尾this[this.length] = arr;Array.prototype.push = function(arr) {       this.length++;}console.log(obj);obj.push("newVal");console.log(obj)

在这里插入图片描述

转载地址:http://yopo.baihongyu.com/

你可能感兴趣的文章
Nginx实现反向代理负载均衡
查看>>
nginx实现负载均衡
查看>>
nginx常用命令及简单配置
查看>>
Nginx常用屏蔽规则,让网站更安全
查看>>
nginx开机启动脚本
查看>>
nginx异常:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf
查看>>
nginx总结及使用Docker创建nginx教程
查看>>
nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:128
查看>>
nginx报错:the “ssl“ parameter requires ngx_http_ssl_module in usrlocalnginxconfnginx.conf128
查看>>
nginx日志分割并定期删除
查看>>
Nginx日志分析系统---ElasticStack(ELK)工作笔记001
查看>>
Nginx映射本地json文件,配置解决浏览器跨域问题,提供前端get请求模拟数据
查看>>
nginx最最最详细教程来了
查看>>
Nginx服务器---正向代理
查看>>
Nginx服务器上安装SSL证书
查看>>
Nginx服务器基本配置
查看>>
Nginx服务器的安装
查看>>
Nginx标准配置文件(包括反向代理、大文件上传、Https证书配置、文件预览等)
查看>>
Nginx模块 ngx_http_limit_conn_module 限制连接数
查看>>
Nginx模块 ngx_http_limit_req_module 限制请求速率
查看>>