当前位置:网站首页>Common methods of array
Common methods of array
2022-07-25 03:07:00 【Gary_ Leong】
Array.push()
Add one or more elements... To the end of the array , And returns the new array length . The original array changes .

Array.forEach(function)
Used to call each element of an array , And pass the element to the callback function . The original array remains the same .( Pay attention to this method and map The difference between , If you print directly Array.forEach, The result is undefined).
Array.map(function)
After each item of the original array executes the function , Returns a new array . The original array remains the same .( Pay attention to this method and forEach The difference between ).
indexOf()
Detect the position index of the current value for the first time in the array
Parameters :array.indexOf(item,start) item: Looking for elements start: The position in the string where the retrieval starts .
Return value : The index found for the first time , No return found -1.
Whether to change the original array : Don't change .
includes()
Determine whether an array contains a specified value .
Parameters : Specified content
Return value : Boolean value
Whether to change the original array : Don't change .
Array.join()
Connect each item of the array with a specified character to form a string . The default connection character is “,” comma .

Array.filter(function)
Filter the array , Qualified elements and return a new array .

Array.some(function)
Judge each item in the array , If none of them meet the requirements, return to false, Otherwise return to true.
Array.pop()
Delete and return the last element of the array , If the array is empty , Then return to undefined. The original array changes .

Array.unshift()
Add one or more elements... To the beginning of the array , And returns the new array length . The original array changes .

Array.shift()
Delete the first item of the array , And returns the value of the first element . If the array is empty , Then return to undefined. The original array changes .

Array.concat(arr1,arr2…)
Merge two or more arrays , Generate a new array . The original array remains the same .

Array.reverse()
Reverse array . The original array changes .

Array.sort()
Sort array elements . According to the string UniCode Sort code , The original array changes .
- From small to large

- From big to small

- Sort by a value in the array object


Array.slice()
Find out some of the contents according to the conditions
Parameters :
array.slice(n, m), From the index n Start finding m It's about ( It doesn't contain m)
array.slice(n) The second parameter is omitted , Then search until the end
array.slice(0) Output content as is , Array cloning can be realized
array.slice(-n,-m) slice Support negative parameters , From the last item ,-1 For the last ,-2 It's the penultimate item
Return value : Returns a new array
Whether to change the original array : Don't change
Array.splice(index,howmany,arr1,arr2…)
Used to add or delete elements in an array . from index Location start delete howmany Elements , And will arr1、arr2… Data from index Insert... In sequence .howmany by 0 when , The element is not deleted . The original array changes .

Array.every(function)
Judge each item in the array , If all match, return true, Otherwise return to false.
Array.reduce(function)
reduce() Method to receive a function as an accumulator , Every value in the array ( From left to right ) Start to shrink , The final calculation is a value .
![[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-Tz3VdecM-1658148983448)(../imgs/array-reduce.png)]](/img/d6/84300aeded60dcc652f1c762371f53.png)
边栏推荐
- JS foundation -- regular expression
- [jailhouse article] certify the uncertified rewards assessment of virtualization for mixed criticality
- [stm32f103rct6] motor PWM drive module idea and code
- Implementation principle of virtual DOM
- Riotboard development board series notes (VIII) -- building desktop system
- IO (1) -io layering
- Bgy development small example
- Solve ''_ Xsrf 'argument missing from post
- Go multiplexing
- TypeScript
猜你喜欢

Arduino + si5351 square wave generator

Request and response

Error: tomee required to support ear/ejb deployment

kettle_ Configure database connection_ report errors
![[Kali's sshd service is enabled]](/img/1b/180534d51049177254e30c4b783eba.png)
[Kali's sshd service is enabled]

Banana pie bpi-m5 toss record (2) -- compile u-boot

Mark down learning

Vulntarget vulnerability shooting range -vulntarget-b

Method of adding kernel in Jupiter notebook

MySQL common function summary, very practical, often encountered in interviews
随机推荐
Reasons for not sending requests after uni app packaging
Color space (2) -- YUV
Method of adding kernel in Jupiter notebook
List.stream common operations
What should I do when the interface encounters jsonstring
[Kali's sshd service is enabled]
Import and export using poi
JS method encapsulation summary
[jailhouse article] scheduling policies and system software architectures for mixed criticality
The file in scanpy1.9.1 cannot be read in scanpy1.7.2. The problem is solved
Brief understanding of operational amplifier
Preliminary foundation JVM
JS construct binary tree
Recursive and non recursive methods are used to realize the first order, middle order and second order traversal of binary tree respectively
Map set learning
Common Oracle commands
Request and response
Dynamic programming -- Digital DP
Sequence diagram of UML diagram series
Resolve the error: org.apache.ibatis.binding.bindingexception