当前位置:网站首页>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
边栏推荐
- At the age of 32, I fell into a middle-aged crisis and finally quit naked...
- MySQL advanced (Advanced SQL statement)
- 【学习强化学习】总目录
- Basic operations of C language
- VLAN access mode
- After getting these performance test decomposition operations, your test path will be more smooth
- UE4_ Editor UMG close window cannot destroy UMG immediately
- MySQL高级SQL语句
- Transfer the token on the matic-erc20 network to the matic polygon
- 超简单 STM32 RTC闹钟 时钟配置
猜你喜欢
2022年,谁在推动音视频产业的新拐点?
Intelligent deodorizer embedded development
English语法_形容词/副词3级-最高级
[ansible series] fundamentals 02 module debug
1380. lucky numbers in matrices
8 ways to earn passive income
Gestion des utilisateurs de la base de données MySQL
I have been working as a software testing engineer for 5 years, but I was replaced by an intern. How can I improve myself?
[MD editing required] welcome to the CSDN markdown editor
Rotating frame target detection mmrotate v0.3.1 training dota data set (II)
随机推荐
SparseArray
超简单 STM32 RTC闹钟 时钟配置
09- [istio] istio service entry
Golang之手写web框架
On line assignment of financial cost management in the 22nd spring of Western Polytechnic University [Full Score answer]
Xi'an Jiaotong 21st autumn economics online homework answer sheet (III) [standard answer]
拼多多店铺搜索相关问题,为什么新品上架搜索不到
What indicators should safety service engineers pay attention to in emergency response?
飞升:基于中文分词器IK-2种自定义热词分词器构建方式showcase & 排坑showtime
Transfer the token on the matic-erc20 network to the matic polygon
MySQL index
Codeforces Round #390 (Div. 2) D. Fedor and coupons
STM32F103系列控制的OLED IIC 4针
重构之美:当多线程批处理任务挑起大梁 - 万能脚手架
Solidity - Security - reentrancy attack
Intelligent question - horse racing question
Mysql database user management
Set of XXL job principles
Voting vault: a new primitive for defi and Governance
Official win 10 image download