当前位置:网站首页>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})边栏推荐
猜你喜欢

数据库设计的酸(ACID)碱(BASE)原则
![[Solved] Unity Coroutine coroutine is not executed effectively](/img/ab/035ef004a561fb98d3dd1d7d8b5618.png)
[Solved] Unity Coroutine coroutine is not executed effectively

开发Hololens遇到The type or namespace name ‘HandMeshVertex‘ could not be found..

2022-08-04T17:50:58.296+0800 ERROR Announcer-3 io.airlift.discovery.client.Announcer appears after successful startup of presto

[TA-Frost Wolf_may-"Hundred Talents Project"] Graphics 4.3 Real-time Shadow Introduction

Flink 1.15.1 Cluster Construction (StandaloneSession)

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

token、jwt、oauth2、session解析

markdown如何换行——md文件

CPDA|How Operators Learn Data Analysis (SQL) from Negative Foundations
随机推荐
Call Alibaba Cloud oss and sms services
Android Practical Development - Kotlin Tutorial (Introduction - Login Function Implementation 3.3)
开发Hololens遇到The type or namespace name ‘HandMeshVertex‘ could not be found..
A small tool to transfer files using QR code - QFileTrans 1.2.0.1
2022 Hangzhou Electric Multi-School 1st Game
ffmpeg pixel format basics
.NET Application -- Helloworld (C#)
2022.8.4-----leetcode.1403
Getting Started with Kubernetes Networking
On governance and innovation, the 2022 OpenAtom Global Open Source Summit OpenAnolis sub-forum came to a successful conclusion
Web3.0 Dapps——通往未来金融世界的道路
You may use special comments to disable some warnings. 报错解决的三种方式
【软件测试】自动化测试之unittest框架
冒泡排序与快速排序
Defect detection (image processing part)
How to discover a valuable GameFi?
36-Jenkins-Job迁移
STM32 uses stm32cubemx LL library series tutorial
Shell script: for loop and the while loop
今年七夕,「情蔬」比礼物更有爱