当前位置:网站首页>js中类数组对象以及类数组转换的方法(ES6, ES5)
js中类数组对象以及类数组转换的方法(ES6, ES5)
2022-07-23 05:39:00 【Vivqst】
js中类数组对象以及类数组转换的方法(ES6, ES5)
类数组(Array-like)对象,通常我们可以把拥有一个length属性和非负整数属性的对象称为类数组对象
JavaScript 数组与一般对象的区别:
- 当有新元素添加到列表中时,自动更新 length 属性
- 设置 length 属性值为一个较小值会截断数组
- 从 Array.prototype 中继承一些有用的方法
- 类属性为「Array」
注:类数组对象的length不会自动更新
常见的类数组对象有:
- document.getElementsByClassName获取的nodeList
- 函数的arguments
// 定义一个类数组
var likeArray = {
0: 'name', 1: 'age', 2: 'sex', length:3}
// ES5
var arr = Array.prototype.slice.call(likeArray)
// ['name', 'age', 'sex']
// ES6
Array.from(likeArray)
边栏推荐
猜你喜欢

JDBC database connection pool

【无标题】

JDBC数据库连接池

Cell sends SMS asynchronously

How to merge the website content with video and audio separated? How to write batch download code?

PyGame realizes the airplane war game
![[flink]flink on yarn之flink-conf最简单配置](/img/de/0ec23f3379148dba27fe77dc51e22f.png)
[flink]flink on yarn之flink-conf最简单配置

Fun code rain, share it online~-

【系统问题】.NET Framework 3.5 安装错误

【文献调研】在Pubmed上搜索特定影响因子期刊上的论文
随机推荐
2. Analysis of the return value of the startup function
【无标题】
Web server failed to start. Port 8080 was already in use.
[监控部署实操]基于granfana展示Prometheus的图表和loki+promtail的图表
JDBC database connection pool
Alipay DTS architecture
从零开始的pytorch小白使用指北
PyGame realizes the airplane war game
[部署]presto-server-0.261.tar.gz的集群部署和启动
【Pyradiomics】提取的影像组学特征值不正常(很多0和1)
【无标题】
[pytho-flask筆記5]藍圖簡單使用
【uiautomation】键指令大全(以及三种调用方式)+常用鼠标动作+SendKeys+Inspect学习
JS, pay attention to passing parameters. If it is a string, you need to add escape characters
知识点回顾
【系统问题】.NET Framework 3.5 安装错误
2.启动函数返回值的剖析
View set and route
Dictionary creation and copying
idea中复制一个项目/project