当前位置:网站首页>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
边栏推荐
- Official win 10 image download
- Intelligent question - horse racing question
- Xi'an Jiaotong 21st autumn online expansion resources of online trade and marketing (II)
- MySQL log management, data backup and recovery
- Force deduction exercise -- deleting repeated items in ordered sequence 1.0
- MySQL index
- Rotating frame target detection mmrotate v0.3.1 learning configuration
- 10-【istio】istio Sidecar
- What indicators should safety service engineers pay attention to in emergency response?
- Basic operations of C language
猜你喜欢

Solidy - fallback function - 2 trigger execution modes

Sound network, standing in the "soil" of the Internet of things

What do you think of the deleted chat records? How to restore the deleted chat records on wechat?
![[Alibaba cloud] student growth plan answers](/img/34/cba975c0960d5595433adcb23f6e64.jpg)
[Alibaba cloud] student growth plan answers

如何制作CSR(Certificate Signing Request)文件?

Intelligent deodorizer embedded development

Tornado frame foundation

1380. lucky numbers in matrices

动态规划--怪盗基德的滑翔翼

About modifying dual system default startup item settings
随机推荐
Set of XXL job principles
UE4_ Editor development: highlight the UI making method according to the assets dragged by the mouse (1)
Navigate back to fragmentpageradapter - & gt; Fragment is empty - navigating back to fragmentpageradapter - & gt; fragments are empty
Stack overflow caused by C # using protobuf stack overflow
Rotating box target detection mmrotate v0.3.1 getting started
Title: enter two positive integers m and N to find their maximum common divisor and minimum common multiple
Transfer the token on the matic-erc20 network to the matic polygon
token 过期后,如何自动续期?
Xi'an Jiaotong automation control theory test simulation question [standard answer]
Video summary of my station B
Intelligent question - horse racing question
UML tools
86. separate linked list
STM32F103系列控制的OLED IIC 4针
[MD editing required] welcome to the CSDN markdown editor
Luogup2756 pilot pairing scheme problem (maximum flow)
Switch to software testing and report to the training class for 3 months. It's a high paying job. Is it reliable?
Xi'an Jiaotong 21st autumn economics online homework answer sheet (III) [standard answer]
English语法_形容词/副词3级-最高级
What do you think of the deleted chat records? How to restore the deleted chat records on wechat?