当前位置:网站首页>Summary of common methods of arrays
Summary of common methods of arrays
2022-08-05 03:32:00 【the wind that fades away the temperature】
1. Array name.push(array)//Add at the end to return a new array after adding
2. Array name.pop(array)//Delete at the end
3. Array name.shift(not requiredPass parameters)//Delete the header
4. Array name.unshift(added data)//Add the header
5. Array name.reverse(array)//Flip and return to the reversed
6. Array name. splice (start index, how many, data to be inserted) // used for array interception delete insertion array (splice will affect the original array)
splice method example:var arr=[1,2,3,4,5,6,7,8] let ad=arr.splice(0,3)//Intercept 3 from the 0 index, you can let ad receive the intercepted dataYou can also not receive and print arr, you will find that three data have been deletedconsole.log(ad);
7. 数组.slice(开始索引,结束索引) 使用slice 截取数组 该方法 不会影响原始数组
8. Array sorting:
Array name.sort(function(a,b){return a-b}) positive order
Array name.sort(function(a,b){return b-a}) flashback
9. Array to String join()
arr=[1,2,3,4]arr.join()prints as 1-2-3-4array name.join('-')
10. Array concatenation concat()
let arr=[1,2,3,4]arr.concat[5,6]prints as [1, 2, 3, 4, 5, 6]
11. Array name.indexOf(data) Find whether the data exists in the array and return the subscript otherwise return -1
//Filter the array
12. filter() array filter
Array.filter(function(item,index,arr){Return the returned array that matches the filter conditions})
This method returns a new filtered array
13. every() determines whether each item meets the conditions
Array.every(function(item,index,arr){return what is returnedThe method returns a boolean value})
14 .some() Determines whether an item in the array satisfies the condition
Array.some(function(item,index,arr){return what is returnedReturns a boolean value})
15. Array name.map() Array mapping
The simple understanding of map is to modify the original array loop operation and then define a variable to receive the returned content
It calls the function for each element of the array, andReturns an array of results.
Example:
let arr = [1,2,3]let arr2 = arr.map(item => item*2)console.log(arr2)//map traverse the new array returned after modificationConsole.log(arr)//Original arrayBy printing, you will find that using the map method does not modify the contents of the original array but returns a new array
16. includes fuzzy query
includes fuzzy querieslet arr = ['Tom', 'jian', 'jierui', 'kk']let strVal2= arr.filter(item =>item.includes('k'))console.log(strVal2);//This method can find the content that meets the conditions in the array. Generally, it is used as a fuzzy search function in the search box with filter filtering.
17.forEach loops through the array
Array name.forEach((item,index) => {Each content of the item arrayindex subscript})
边栏推荐
- 引领数字医学高地,中山医院探索打造未来医院“新范式”
- Never put off till tomorrow what you can put - house lease management system based on the SSM
- Native js realizes the effect of selecting and canceling all the multi-select boxes
- 2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer appears after successful startup of presto
- GC Gaode coordinate and Baidu coordinate conversion
- token、jwt、oauth2、session解析
- Redis key基本命令
- The most effective seven performance testing techniques of software testing techniques
- 【Daily Training】1403. Minimum Subsequence in Non-Increasing Order
- 队列题目:最近的请求次数
猜你喜欢
Solana NFT开发指南
通过模拟Vite一起深入其工作原理
Industry Status?Why do Internet companies prefer to spend 20k to recruit people rather than raise their salary to retain old employees~
Dynamic management of massive service instances
用Unity发布APP到Hololens2无坑教程
Why is the pca component not associated
[Filter tracking] based on matlab unscented Kalman filter inertial navigation + DVL combined navigation [including Matlab source code 2019]
大像素全景制作完成后,推广方式有哪些?
银行数据采集,数据补录与指标管理3大问题如何解决?
public static <T> List<T> asList(T... a) 原型是怎么回事?
随机推荐
.NET应用程序--Helloworld(C#)
ffmpeg enumeration decoders, encoders analysis
冰蝎V4.0攻击来袭,安全狗产品可全面检测
Open-Falcon of operation and maintenance monitoring system
思考(八十八):使用 protobuf 自定义选项,做数据多版本管理
Why did they choose to fall in love with AI?
dmp (dump) dump file
Question about #sql shell#, how to solve it?
The pit of std::string::find return value
ffmpeg 像素格式基础知识
阿里本地生活单季营收106亿,大文娱营收72亿,菜鸟营收121亿
ffmpeg pixel format basics
[Qixi Festival] Romantic Tanabata, code teaser.Turn love into a gorgeous three-dimensional scene and surprise her (him)!(send code)
毕设-基于SSM房屋租赁管理系统
2022高处安装、维护、拆除考试题模拟考试题库及在线模拟考试
Android Practical Development - Kotlin Tutorial (Introduction - Login Function Implementation 3.3)
大佬们,我注意到mysql cdc connector有参数scan.incremental.sna
Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)
Initial solution of the structure
Step by step how to perform data risk assessment