8: JavaScript array usage method
()
Convert all elements of the array into String, and then join, you can specify an optional String separation element, which defaults to ","
var s = (); ==> s="1,2,3"
s = (","); ==> s="1, 2, 3"! The results are slightly different
() is the opposite of () (split String into several pieces to build an Array)
()
() Reverse the order of array elements and return the reversed array, perform the operation on the original array
(); ==> a[1] = 3, a[2] = 2, a[3] = 1
var s = (); ==>s = "3,2,1"
()
() Sort elements on the original array, return the sorted array, sorted by letter by default, otherwise the comparison function should be passed as sort() parameter
();
var s = ("/"); ==>s = "A/ B/ C";
var a = [1, 3, 4];
(
function(a,b)
{
return a - b;
}
) ; ==>according to<0,0,>0 Return1, 3, 4
toLowerCase(), toUpperCase() converts letter case
()
create, and return array contains the elements in the original array that calls concat(), followed by the concat() parameter. If it is an array, it will be expanded
But it cannot be expanded recursively
(4,5); ==>[1,2,3,4,5]
([4,5], [6,7]); ==>[1,2,3,4,5,6,7]
(4, [5, [6, 7]]); ==>[1,2,3,4,5,[6,7] ]
()
() return specifies a slice of the array, two parameters specify the start and end of the segment to be returned, and the array contains one parameter but does not contain two parameters
If there is only one parameter and no two parameters, return all elements after it from one parameter. If there is one parameter, it is relative to the last element of the array.
-1 specifies the last elements of the array, -3 specifies the last element of the array, the third end of the end element
(0,3); ==>[1,2,3]
(3); ==>[4,5]
(1,-1); ==>[2, 3, 4]
(-3, -2); ==>[3]
()
() is insert or delete or insert delete elements generic method. It is modified on the original array. Elements located after insert or delete will be moved necessary.
The first two parameters refer to the delete parameter one of which specifies the location in the array to be deleted. The second parameters specify the number of elements to be deleted. After these two parameters, there can be N parameters, specify the elements to be inserted from the location specified by the parameter one.
var (4); ==>return[5,6,7,8] a=[1,2,3,4]
(1,2); ==>return[2,3] a=[1,4]
(1,1); ==>return[4] a=[1]
var a = [1,2,3,4,5]
(2,0,'a','b'); ==>Return to [] a=[1,2,'a','b',3,4,5]
(2,2,[1,2},3); ==>return['a','b'] a =[1,2,3,[1,2],3,3,4,5]
() pop()
Use array like stack(), modify it on the original array, FILO(first in last out)push() appends multiple elements to the end of the array, return the new array length pop() instead deletes the last element of the array, reduces the length of the array(), return is deleted.
(1,8); ==>[1,8] return 2
(); ==>[1] return 8
(3); ==>[1,3] return 2
(); ==>[1] return 3
(); ==>[1,[4,5] ] return 2
(); ==>[1] return [4,5]
(); ==>[] return [1]
() shift()
Similar to push() pop(), it is just insert delete at the head of the array instead of unshift() return the new array length, insert N elements, shift() returns the first element of the new array at one time
(1); ==>a:[1] return 1
(22); ==>a:[22,1] return 2
(); ==>a:[1] return22
(3, [4,5]); ==>a:[3,[4,5]],1] return 3
() ==>a:[[4,5], 1] return 3
() ==> a:[1] return[4,5]
() ==>a:[] return 1
9.toString() toSurce()
[1,2,3].toString(); ==>"1,2,3"
['a', "b", "c"].toString(); ==>"a,b,c"
[1,[2.'c']].toString(); ==>"1,2,c"
toLocaleString() is a localized version of toString, which will call the toLocaleString() method of each element to convert array elements into String. Then connect the generated String with locally specific (and defined implementations) delimiters