Definition and usage
The push method adds one or more elements to the end of the array and returns a new length.
The join method is used to add all elements in the array to a specified string, and the elements are divided by the specified delimiter.
grammar
arrayObject.push(newelement1,newelement2,...,newelementX)arrayObject.join(separator).
Parameter description newelement1 is required. The first element to be added to the array. newelement2 is optional. The second element to be added to the array. newelementX is optional. Multiple elements can be added.
Parameter description The separator is to stitch "," by default, and you can also specify the separator to use.
example:
var arr = [1,2];console.log("arrBegin-->"+arr);alert(arr.push(3,4));console.log("arrNew-->"+arr);var joinStr = arr.join();console.log("joinStr1--->"+joinStr);var joinStr = arr.join("");console.log("joinStr2--->"+joinStr);var joinStr = arr.join(".");console.log("joinStr3--->"+joinStr);Output result
arrBegin-->1,2alert(4);arrNew-->1,2,3,4joinStr1--->1,2,3,4]joinStr2--->1234joinStr3--->1.2.3.4
The above is a detailed explanation of the push() and join() function examples in JavaScript introduced to you by the editor. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support to Wulin.com website!