当前位置:网站首页>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})
边栏推荐
- 通过模拟Vite一起深入其工作原理
- ASP.NET application--Hello World
- Queue Topic: Recent Requests
- Use Unity to publish APP to Hololens2 without pit tutorial
- [Software testing] unittest framework for automated testing
- [GYCTF2020]EasyThinking
- Dameng 8 database export and import
- AI + Small Nucleic Acid Drugs | Eleven Completes $22 Million Seed Round Financing
- MRTK3开发Hololens应用-手势拖拽、旋转 、缩放物体实现
- .NET Application -- Helloworld (C#)
猜你喜欢
银行数据采集,数据补录与指标管理3大问题如何解决?
The most effective seven performance testing techniques of software testing techniques
How to discover a valuable GameFi?
Developing Hololens encountered The type or namespace name 'HandMeshVertex' could not be found..
Hard power or soft power, which is more important to testers?
shell脚本:for循环与while循环
基于生长的棋盘格角点检测方法
21 Days Learning Challenge (2) Use of Graphical Device Trees
引领数字医学高地,中山医院探索打造未来医院“新范式”
七夕节代码表白
随机推荐
从“能用”到“好用” 国产软件自主可控持续推进
Use SuperMap iDesktopX data migration tool to migrate ArcGIS data
Static method to get configuration file data
[论文笔记] MapReduce: Simplified Data Processing on Large Clusters
Ffmpeg - sources analysis
Why is the pca component not associated
Never put off till tomorrow what you can put - house lease management system based on the SSM
burp安装及代理设置
STM32 uses stm32cubemx LL library series tutorial
Thinking (88): Use protobuf custom options for multi-version management of data
Growth-based checkerboard corner detection method
sql怎么找字段里所有数据为空的字段
ASP.NET application--Hello World
Summary of domestic environments supported by SuperMap
leetcode-每日一题1403. 非递增顺序的最小子序列(贪心)
为什么pca分量没有关联
IJCAI2022 | DictBert: Pre-trained Language Models with Contrastive Learning for Dictionary Description Knowledge Augmentation
shell脚本:for循环与while循环
rpc-remote procedure call demo
Leading the highland of digital medicine, Zhongshan Hospital explores to create a "new paradigm" for future hospitals