Home > Article > Web Front-end > Introduction to javascript array attributes and how to use them
Add array elements
1. arrayt.splice(index,howmany,item1,...,itemX )
Add/remove items to/from the array, and then return the deleted item
2. array.unshift()
Add one or more new elements At the beginning of the array, the elements in the array are automatically moved backward and the new length of the array is returned
3. array.push(newelement1,newelement2,....,newelementX)
Move one or more New elements are added to the end of the array and the new length of the array is returned
Deleting array elements
1. array.pop ()
Deleting and returning the last element of the array will change the length of the original array
2. arrayt.splice(index,howmany,item1,.... .,itemX)
Add/remove items to/from the array, and then return the deleted item
3. array.shift()
Change the first Delete elements from it and return the value of the first element, which will change the length of the original array
Interception and merging of arrays
1. array.slice( start,end)
Return selected elements from an existing array
2. array.concat(arrayX,arrayX,......,arrayX)
(arrayX can be a specific value or an array object. It can be any number)
Used to connect two or more arrays
var a = [1,2,3]; document.write(a.concat(4,5)); 结果为[1,2,3,4,5]
Copy of array
1. array.slice(start,end)
Return the selected element from the existing array
2. array.concat(arrayX,arrayX,...,arrayX)
(arrayX can be a specific value or an array object. It can be any number)
Used to join two or more arrays
var a = [1,2,3]; document.write(a.concat(4,5)); 结果为[1,2,3,4,5]
Sorting of array elements
1 .array.sort(sortby)(soetby is optional and must be a function)
Sort the array elements
2. array.reverse()
Reverse the order of the array
Stringification of array elements
1. array.join(separator)
(separatorspecifies the separator to be used. If this parameter is omitted, commas are used as delimiters)
Put all elements of the array into a string. Elements are separated by the specified delimiter.
2. array.toString()
Convert array to string
The above is the detailed content of Introduction to javascript array attributes and how to use them. For more information, please follow other related articles on the PHP Chinese website!