当前位置:网站首页>Es6数组
Es6数组
2022-06-30 05:58:00 【SignalFire】
1、伪数组转数组
(1)Array.prototype.slice.call()
let divs = document.getElementsByTagName("div");
let arr = Array.prototype.slice.call(divs);
console.log(arr);
(2)Array.from()
let arrObj = {
1:"aa",
0:"bb",
length:2
}
let arr = Array.from(arrObj);
console.log(arr);
(3)Array.of()
let arr = Array.of(1,"a",false,[2,3],{a:"asdf"});
console.log(arr);
let arr = Array.of(1,2,3,4);
console.log(arr);
2、元素替换
(1)arr.copyWithin(i,j1[,j2]) 用j1到j2的元素替换从i开始的对应元素,j2省略则j1到末尾
let arr = [0,1,2,3,4,5,6,7,8,9];
arr = arr.copyWithin(2,5,7);
console.log(arr);
(2)arr.fill(newVal[,j1,j2]) 用newVal替换从j1到j2的元素,j1,j2不写则替换所有元素
let arr = [0,1,2,3,4,5,6,7,8,9];
arr = arr.fill("newVal",5,8);
console.log(arr);
3、检测元素是否存在
includes(item)
let arr = [1,2,3,NaN]
console.log(arr.includes(NaN));
indexOf不能检测NaN
边栏推荐
- Set of XXL job principles
- [GPU] basic operation
- [ansible series] fundamentals -01
- Xi'an Jiaotong automation control theory test simulation question [standard answer]
- [OSPF] comparison between rip and OSPF
- Acwing winter vacation daily question 2022 punch in day 11
- Intelligent question - horse racing question
- 领导:谁再用 Redis 过期监听实现关闭订单,立马滚蛋!
- Gestion des utilisateurs de la base de données MySQL
- Xctf attack and defense world crypto advanced area
猜你喜欢

Huxiaochun came to fengshu electronics to sign a strategic cooperation agreement with Zoomlion

C语言基础小操作

Projet Web de déploiement du serveur Cloud

声网,站在物联网的“土壤”里

Summation of basic exercise sequence of test questions

Official win 10 image download

What indicators should safety service engineers pay attention to in emergency response?

Basic operations of C language

【板栗糖GIS】global mapper—如何把栅格的高程值赋予给点

MySQL日志管理、数据备份、恢复
随机推荐
How to write a thesis
Force deduction exercise -- deleting repeated items in ordered sequence 1.0
[OSPF] comparison between rip and OSPF
token 过期后,如何自动续期?
Shenzhou ares tx6 boot logo modification tutorial
Rotating box target detection mmrotate v0.3.1 getting started
[exercise] basic practice letter graph of Blue Bridge Cup
Strlen and sizeof, array length and string length, don't be silly
Xi'an Jiaotong 21st autumn economics online homework answer sheet (III) [standard answer]
MySQL存储系统
[untitled] user defined function
InputStream转InputStreamSource
Who is promoting the new inflection point of audio and video industry in 2022?
声网,站在物联网的“土壤”里
luoguP2756 飞行员配对方案问题(最大流)
MySQL 索引
Implementation of property management system with ssm+ wechat applet
Cisco VXLAN配置
What indicators should safety service engineers pay attention to in emergency response?
Idea of capturing mobile terminal variant combination