当前位置:网站首页>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
边栏推荐
- Answer sheet for online assignment of "motor and drive" of Xijiao 21 autumn (IV) [standard answer]
- How does WPS cancel automatic numbering? Four options
- 从零开发 stylelint规则(插件)
- token 过期后,如何自动续期?
- [exercise] basic practice letter graph of Blue Bridge Cup
- Using lazy < t > in C # to realize singleton mode in WPF
- Navigate back to fragmentpageradapter - & gt; Fragment is empty - navigating back to fragmentpageradapter - & gt; fragments are empty
- 【学习强化学习】总目录
- Acwing winter vacation daily question 2022 punch in day 11
- Leetcode56. consolidation interval
猜你喜欢

8 ways to earn passive income

The average salary of software testing in 2022 has been released. Have you been averaged?

Solitidy - fallback 回退函数 - 2种触发执行方式

How to automatically renew a token after it expires?

VLAN access mode

token 过期后,如何自动续期?

Gestion des utilisateurs de la base de données MySQL

1380. lucky numbers in matrices

Rotating box target detection mmrotate v0.3.1 getting started

谁不想要一个自己的博客网站呢 - 搭建博客网站wordpress
随机推荐
谁不想要一个自己的博客网站呢 - 搭建博客网站wordpress
Strlen and sizeof, array length and string length, don't be silly
InputStream转InputStreamSource
After getting these performance test decomposition operations, your test path will be more smooth
Acwing winter vacation daily question 2022 punch in day 11
从零开发 stylelint规则(插件)
Intelligent question - horse racing question
MySQL advanced (Advanced SQL statement)
24、 I / O device model (serial port / keyboard / disk / printer / bus / interrupt controller /dma and GPU)
MySQL storage system
86. separate linked list
STM32F103系列控制的OLED IIC 4针
MySQL index
Inno setup the simplest user-defined interface effect
电脑查看WiFi使用密码
ECS deployment web project
InputStream to inputstreamsource
云服务器部署 Web 项目
Transfer the token on the matic-erc20 network to the matic polygon
What kind of answer has Inspur given in the big AI model landing test?