In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail what the common methods of Javascript array are, and the editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
1.push adds one or more elements to the array at the end of the array, and the method returns the length of the new array.
Arr.push (200) arr.push (200jin2) 32)
2.pop deletes an element at the end of the array without passing parameters, and the method returns the deleted element.
Arr.pop ()
3.unshift adds one or more elements to the array to the front, and the return value is the length of the new array.
Arr.unshift (1) arr.unshift (1)
The first element of the 4.shift delete array returns the deleted element.
Arr.shift ()
5. Concat splices two arrays and returns the stitched array. The original array remains unchanged.
Let arr1 = [1mai 2] let arr2 = [2je 3] arr1.concat (arr2) console.log (arr1); / / [1m 2] console.log (arr1.concat (arr2)); / / [1m 2m 2m 2m 3]
6. Reverse array upside down, return the inverted array, the original array changed.
Arr.reverse ()
The interception of the 7.slice array, including the beginning, but not the end, returns the truncated array, and the original array remains unchanged.
Let arr = [1, 5arr.slice 2, 3, 4, 5, 5, 6] / fill in two parameters: a, b, intercept from a to b, not including b, enter a parameter, a, intercept from a to the end, / / leave it unfilled, intercept 3-5 in the last arr, that is, array subscript 2-4, but the second parameter is not included, so it is 2-5arr.slice (2pr 5).
The addition or deletion of the 8.splice array returns an array of deleted elements, with the original array changed.
/ / usage splice / / an indicates the starting subscript of addition or deletion / / b indicates that the number of deletions does not want to be deleted, but only wants to add b to write as 0 pact. C means to add elements that can be added without adding, cvar arr = [1, 2, 3, 4, 4, 5, 6] / / replace 4 with 10arr.splice (3, 1, 10)
9.join concatenates all the elements in the array with a value, which is concatenated by default. The return value is a concatenated string, and the original array remains unchanged.
Let arr = [1, 2, 3, 4, 5, 6] arr.join () arr.join ('-')
10.indexOf detects whether there is an element in the array, and if so, returns the subscript found for the first time, does not return-1, and the original array remains unchanged.
Let arr = [1, let ind 2, 3, 4, 5, 6] let ind = arr.indexOf (5)
11.lastIndexOf is used in the same way as indexOf, starting at the end of the array.
12.includes detects the existence of an element in the array. Returning true is the same as indexOf in returning false.
13.sort sorts the array and returns the sorted array. The original array changes.
/ / Chinese characters look at strokes, English alphabet, because the alphabetical order / / default sorting is let arr = [2magin 3jing5je 4jing9jue 6] arr.sort () / / sort can write the function / / return b represents the two adjacent numbers in the array / / from small to large row arr.sort (function (aprit b) {return a-b})
14.every checks whether all elements in the array satisfy a condition, has a required parameter, and returns a Boolean value.
Let arr = [100J 1550110] let myarr = arr.every (function (el) {return el > 14}) console.log (myarr) / / true
15.some detects whether an element in the array meets a condition, has a required parameter, and the return value is a Boolean.
Var arr = [100J 1550110] var myarr1 = arr.some (function (el) {return el > 100}) console.log (myarr1) / / true
16.find returns the value of the first element that matches in the array, does not return undefined, and has a required parameter.
Var arr = [100J 1550110] var myarr2 = arr.find (function (el) {return el > 10}) console.log (myarr2) / / 100
The 17.findIndex method is the corresponding index value with the return value of find.
18.filter returns qualified elements to form a new array, and the return value is an array.
Var arr = [100,15,8pm 50110] var myarr3 = arr.filter (function (el) {return el)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.