Sort Sorts the elements of an array in place and returns the array. Syntax array.sort([compareFunction]) Example The following example creates four arrays and displays the original array, then the sorted arrays. The numeric arrays are sorted without, then with, a compare function. This example produces the following output. As the output shows, when a compare […]
Reverse Reverses an array in place. The first array element becomes the last and the last becomes the first. Syntax array.reverse() Example The following example creates an array myArray, containing three elements, then reverses the array. This code changes myArray so that: myArray is “three” myArray is “two” myArray is “one”
Push Adds one or more elements to the end of an array and returns the new length of the array. Syntax array.push(element1, …, elementN) Example The following code creates the sports array containing two elements, then appends two elements to it. After the code executes, sports contains 4 elements: “soccer”, “baseball”, “football” and “swimming”.
pop Removes the last element from an array and returns that element. Syntax array.pop() Example
The array object provides a sort method that does just this: It returns a comma-separated list of the elements in sorted order. Sorting is performed in ascending order alphabetically or numerically as appropriate. To use the method, simply call it: Syntax: arrayName.sort(); Example: Output: Apple, Banana, Mango, Orange
The String() function converts the value of an object to a string. Syntax String(object) Example Output true false true false Sat Jul 30 2011 16:46:32 GMT+0500 (West Asia Standard Time) 999 888 12345