当前位置:网站首页>ES6 array method
ES6 array method
2022-06-29 13:47:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
Array Array
In order to supplement some defects of some methods in the original array ,ES6 Add a lot more in the array API Such as Array.from include fill wait .
Array.from()
The API It can be used to convert class arrays and convenient objects to arrays , such as function Medium arguments object ( An array of class ),set map es6 New traversable objects
function test () {
var arr = Array.from(arguments);
console.log(arr);
}
test(1,2,3); // [1,2,3]
For browsers that are not yet compatible with this method, you can use slice Instead of
[].slice.call(obj) // The same result will be returned
TIP
This function can also accept the second parameter , Be similar to map Method For each element
Array.from(obj,(i) => i*i) // For each element squared Array,of()
Used to convert a set of numbers into an array
var arr = Array.of(1,2,3,4) // [1,2,3,4]Of the array instance find And findIndex
find Method is used to find the first qualified on the array value , And return it
such as [1,2,5,6,2,4];
We want to find the first... On this array value Greater than 5 Number of numbers
[1,2,5,6,2,4].find((item) => item > 5) // 6
If you find the last value that does not meet the condition So return undefined
findIndex Used to return the subscript of the first value in the array that satisfies the condition
[1,2,5,6,2,4].find((item) => item > 5) // 3
If you find the last one that doesn't meet the conditions , Then the return -1
And very important , These two functions can actually NaN 了
[NaN].find((item) => Object.is(NaN,item)) // NaNArray instance fill
fill(item,start,end)
Give a value , Use this value to fill the entire array , This function can also take two arguments , A starting position , An end position
When you use this function to fill in , When only the first parameter is given , Will directly fill the entire array , Whether or not there is a value at a certain position Of the array instance entries keys values
entries => [key,value]
keys => key Subscript
values => value value
for(let [index,value] of arr.entries()){
console.log(index,value)
}Of the array instance includes
Used to detect whether an array contains a value And back to One bool value
include(item,st=0)
The first parameter is the value used to detect
The second parameter is the starting position of the probe The default is 0 Start
If the browser does not support this method , It can also be used. some Method Instead of Array derivation ES7
var a1 = [1,2,3,4]
var a2 = [for (i of a1) i*2] // [2,4,6,8]Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/132369.html Link to the original text :https://javaforall.cn
边栏推荐
- Weserver publishing map service
- LeCun用62页论文公布未来十年研究计划:AI自主智能
- 【系统设计】邻近服务
- Check yaml file security configuration: kubesec
- Yolo series combs (IX) first taste of newly baked yolov6
- mybaits入门(含实例教程和源码)
- Use Gerrit + Zadig to realize trunk development and trunk publishing (including byte flying Book Practice)
- 3个最佳实践助力企业改善供应链安全
- [system design] proximity service
- MySQL常用语句和命令汇总
猜你喜欢

mysql调优

记一次 .NET 某物管后台服务 卡死分析

The imshow function of Matplotlib displays grayscale images. Vmin and vmax2 parameters should be set

Cloud native (31) | kubernetes chapter kubernetes platform basic pre installed resources

How to make dapper support dateonly type

Ordinary users use vscode to log in to SSH and edit the root file

Server monitoring netdata panel configuring mail service
![[cloud resident co creation] break through the performance bottleneck of image recognition through rust language computing acceleration technology](/img/1a/c5e1e17d057c8b4ba2e57f28237498.png)
[cloud resident co creation] break through the performance bottleneck of image recognition through rust language computing acceleration technology

weserver發布地圖服務

揭秘!付费会员制下的那些小心机!
随机推荐
请问老师炒期货怎么设定安全线和安全边际?
技术分享| 融合调度中的广播功能设计
urllib urllib2
极光 · 哈夫曼树の生成(线段树结构 非指针)(仿邻接表)
揭秘!付费会员制下的那些小心机!
Summary of common MySQL statements and commands
C language memory function
Check yaml file security configuration: kubesec
Detailed explanation of PDB symbol library files
Cvpr2022 | panopticdepth: a unified framework for depth aware panoramic segmentation
Is it safe to open an account online?
Don't build the wheel again. It is recommended to use Google guava open source tool class library. It is really powerful!
DeeCamp2022正式开营!李开复、张亚勤亲授大师课 | 创新事
How to make dapper support dateonly type
C language character function
Hundreds of CVPR people were recruited as new champions. Emoji became a "court witness". M2 MBP was exposed that the hard disk speed was reduced. Today, more big news is here
The imshow function of Matplotlib displays grayscale images. Vmin and vmax2 parameters should be set
Valueerror: only TF native optimizers are supported in Eagle mode
Learn from the official motor and BLDC control strategies, and make money as soon as you learn
LeCun用62页论文公布未来十年研究计划:AI自主智能