Home > Article > Web Front-end > JavaScript local objects
Javascript objects include: JS Array (array object), JS Boolean (Boolean object), JS Date (date object), JS Math (Math object), JS Number (numeric object), JS String (string object), JS RegExp (regular expression), JS Function (function object), Window and Screen in Browser, etc.
Method | Description |
---|---|
Concatenates two or more arrays and returns the result. | |
Put all elements of the array into a string. Elements are separated by the specified delimiter. | |
Deletes and returns the last element of the array | |
Adds one or more elements to the end of an array and returns the new length. | |
Reverse the order of elements in the array. | |
Delete and return the first element of the array | |
Return selected elements from an existing array | |
Sort the elements of the array | |
Returns the source code of the object. | |
Convert the array to a string and return the result. | |
Convert the array to a local array and return the result. | |
Adds one or more elements to the beginning of the array and returns the new length. | |
Return the original value of the array object |
<script type="text/javascript">var a = [1,2,3]; document.write(a.concat(4,5));</script>Output:
1,2,3,4,5Join() creates an array and puts all its elements into a string:
<script type="text/javascript">var arr = new Array(3) arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"document.write(arr.join())</script>Output:
George,John,Thomassort() will create an array to sort
<script>var x=[4,5,7,1,6,9,3,10,132,12]; console.log(x.sort()); console.log(x.sort(function(a,b){ return a-b; })); console.log(x.sort(function(a,b){ return b-a; })) ; console.log(x);</script>Output:
[1, 10, 12, 132, 3, 4, 5, 6, 7, 9] [1, 3, 4, 5, 6, 7, 9, 10, 12, 132] [132, 12, 10, 9, 7, 6, 5, 4, 3, 1] [132, 12, 10, 9, 7, 6, 5, 4, 3, 1]pop() creates an array and then deletes the array the last element of . Note that this will also change the length of the array:
<script type="text/javascript">var arr = new Array(3) arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"document.write(arr) document.write("<br />") document.write(arr.pop()) document.write("<br />") document.write(arr)</script>Output:
George,John,Thomas Thomas George,Johnpush() method adds one or more elements to the end of the array and returns the new length.
<script type="text/javascript">var arr = new Array(3) arr[0] = "George"arr[1] = "John"arr[2] = "Thomas"document.write(arr + "<br />") document.write(arr.push("James") + "<br />") document.write(arr)</script>Output:
George,John,Thomas 4 George,John,Thomas,JamesThis article explains the local objects of JavaScript. For more related content, please pay attention to the php Chinese website. Related recommendations:
Introducing a small case for getting started with JS
Achieving dynamic display of processes through js
particlesJS usage introduction related content
The above is the detailed content of JavaScript local objects. For more information, please follow other related articles on the PHP Chinese website!