当前位置:网站首页>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})边栏推荐
- Android Practical Development - Kotlin Tutorial (Introduction - Login Function Implementation 3.3)
- 七夕节代码表白
- Thinking (88): Use protobuf custom options for multi-version management of data
- Walter talked little knowledge | "remote passthrough" that something
- 通过模拟Vite一起深入其工作原理
- Dameng 8 database export and import
- Object.defineProperty monitors data changes in real time and updates the page
- ffmpeg enumeration decoders, encoders analysis
- 用CH341A烧录外挂Flash (W25Q16JV)
- Why is the pca component not associated
猜你喜欢

ASP.NET应用程序--Hello World

dmp (dump) dump file

Industry Status?Why do Internet companies prefer to spend 20k to recruit people rather than raise their salary to retain old employees~

Intersection of Boolean Operations in SuperMap iDesktop.Net - Repairing Complex Models with Topological Errors

Developing Hololens encountered The type or namespace name 'HandMeshVertex' could not be found..

Question about #sql shell#, how to solve it?

为什么pca分量没有关联

markdown如何换行——md文件

36-Jenkins-Job迁移
![[Software testing] unittest framework for automated testing](/img/80/caedd5cf6dd61c9d75475866613cac.png)
[Software testing] unittest framework for automated testing
随机推荐
.NET Application -- Helloworld (C#)
开发Hololens遇到The type or namespace name ‘HandMeshVertex‘ could not be found..
如何在WordPress中添加特定类别的小工具
Package zip is not available, but is referred to by another package.
今年七夕,「情蔬」比礼物更有爱
数据库设计的酸(ACID)碱(BASE)原则
public static <T> List<T> asList(T... a) 原型是怎么回事?
队列题目:最近的请求次数
Solana NFT开发指南
2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer appears after successful startup of presto
XMjs cross-domain problem solving
剑指Offer--找出数组中重复的数字(三种解法)
【Daily Training】1403. Minimum Subsequence in Non-Increasing Order
The pit of std::string::find return value
Use @Mapper to query the partition status of oracle and report an error
冰蝎V4.0攻击来袭,安全狗产品可全面检测
905. 区间选点
Never put off till tomorrow what you can put - house lease management system based on the SSM
数组常用方法总结
调用阿里云oss和sms服务