Home > Article > Web Front-end > Introduction to array operations in JavaScript_javascript skills
The array object in JavaScript comes with some methods, and you can use these methods to operate on the array.
join()
You can use the join() method to combine members of an array into a string:
As you can see from the above example, if the join() method takes no parameters, JavaScript will use commas as delimiters to merge all members into a string; if the join() method accepts parameters, then this parameter will be used as separator to use.
reverse()
You can use the reverse() method to reverse the order of members in the array:
As you can see, after calling the reverse() statement, the array itself will change.
The return result of executing the reverse() statement is the changed array object.
sort()
You can use the sort() method to sort the members in the array (alphabetical order by default). Like the reverse() statement, the sort() statement modifies the array itself and returns the modified array object:
As you can see, the sort() statement also accepts a function as a parameter to implement custom sorting.
concat()
You can use the concat() method to concatenate arrays:
As you can see, unlike reverse() and sort(), the concat() statement only returns the spliced result and does not cause any modification to the array itself.
slice()
You can use the slice() statement to get the sub-array in the array:
splice()
You can use the splice() statement to perform insertion and deletion operations on the array. The first parameter specifies the position of insertion or knockout (positional member), the second parameter specifies the number of knockout members (starting to knockout from the positional member), starting from the third parameter, all parameters will be inserted into In the array (insert from before position member). The result returned by the splice() statement is an array composed of the deleted array members. Unlike concat() and slice(), splice() will modify the array itself.