当前位置:网站首页>ES6 array
ES6 array
2022-06-30 06:04:00 【SignalFire】
1、 Pseudo array to array
(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、 Element substitution
(1)arr.copyWithin(i,j1[,j2]) use j1 To j2 Element replacement from i Start with the corresponding element ,j2 Ellipsis j1 To the end
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]) use newVal Replacement from j1 To j2 The elements of ,j1,j2 Replace all elements without writing
let arr = [0,1,2,3,4,5,6,7,8,9];
arr = arr.fill("newVal",5,8);
console.log(arr);
3、 Check whether the element exists
includes(item)
let arr = [1,2,3,NaN]
console.log(arr.includes(NaN));
indexOf Can 't detect NaN
边栏推荐
猜你喜欢
Configure the user to log in to the device through telnet -- AAA local authentication
SparseArray
Strlen and sizeof, array length and string length, don't be silly
雲服務器部署 Web 項目
Tornado frame foundation
JS prototype chain object function relationship
[secretly kill little partner pytorch20 days] - [day4] - [example of time series data modeling process]
Summation of basic exercise sequence of test questions
What indicators should safety service engineers pay attention to in emergency response?
[Alibaba cloud] student growth plan answers
随机推荐
ECS deployment web project
MySQL transaction
Related applications of priority queue
MySQL数据库用户管理
旋转标注工具roLabelImg
Swoole process model diagram
Share problems solved
At the beginning of 2022, people who are ready to change jobs should pay attention to
Force deduction exercise -- deleting repeated items in ordered sequence 1.0
Implementation of property management system with ssm+ wechat applet
01. 正则表达式概述
IP TCP UDP network encryption suite format
Common address collection
Configure the user to log in to the device through telnet -- AAA local authentication
动态规划--怪盗基德的滑翔翼
Voting vault: a new primitive for defi and Governance
反編譯正常回編譯出現問題自己解决辦法
谁不想要一个自己的博客网站呢 - 搭建博客网站wordpress
MySQL advanced SQL statement
Sword finger offer 29 Print matrix clockwise