This time I will bring you a detailed explanation of the steps to use the JS array method. What are theprecautionswhen using the JS array method? The following is a practical case, let’s take a look.
Function:Splice thearrayinto astring by specifying characters.
Syntax:stringarr.join([separator = ',']);
Parameters:separator can If omitted,defaults to a comma. Ifseprator is an empty string, then all elements in the array will beconcatenateddirectly.
Return value:The concatenated string.
Function:Add one or more elements to theendof the array.
Syntax:number arr.push(element1, ..., elementN);
Parameters:elementN, one or more elements.
Return value:The length of the new array.
Note:will modify the original array.
Function:Add one or more elements to theheadof the array.
Syntax:number arr.push(element1, ..., elementN);
Parameters:elementN, one or more elements.
Return value:The length of the new array.
Note:will modify the original array.
Function:DeletearrayLastaelement.
Syntax:mixed arr.pop();
Return value:The deleted element.
Note:will modify the original array.
Function:Delete the firstelementof the array.Syntax:
mixed arr.pop();Return value:
The deleted element.Note:
will modify the original array.
Merge the incomingarray or non-array valuewith theoriginal array, form anew array and return.Syntax:
array array.concat(value1, value2, ..., valueN);Parameters:
valueN refers to the array or non-array value that needs to be merged with the original array.Return value:
Merged arrayNote:
will notmodify the contents of the original array.
Reverse the position of the elements in the array.Syntax: array arr.reverse( )
Return value:
The array after reversing the orderNote:
willchange the original array.
Syntax:
array arr.slice([begin[,end]]);Return value:
The new array ofafter interceptionNote:
Contains thestarting position,does not includeincludes the ending position,will notchange the original array.If nothing is passed in, the original array will be array.
Syntax:
array array.splice(start,deleteCount[, item1[, item2[, ...]]])Parameters:
- start 起始位置 - deleteCount 删除长度 - item 添加的内容
array composed of the deleted elementsNote:
modifies the contents of the original array.
作用:对数组的元素进行排序。
语法:array arr.sort([compareFunction]);
参数:compareFunction可选。用来指定按某种顺序进行排列的函数。如果省略,元素按照转换为的字符串的诸个字符的Unicode位点进行排序。
返回值:排序后的数组.
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
The above is the detailed content of Detailed explanation of steps to use JS array method. For more information, please follow other related articles on the PHP Chinese website!