Array in JS:
Array is collection of values that belonging into same type.
Syntax:
1)We can use the array literal method to create an array.
array_name = [value1,value2,value3..]; (or)
2)We can also use built-in array constructor new Array method to create an array.
array_name = new Array(value1,value2,..); (or)
3)We can create empty array by passing numeric argument to the Array constructor..
array_name = new Array(size);
Code:
In Browser:
Output:
Before performing array functions:
After performing array functions:
In Console:
Output:
Array Sort & Reverse:
The sort() is used to sort array elements alphabetically.The reverse() is used to reverse the array elements.
Code:
In Browser:
Output:
Before Sorting:
After Sorting:
In Console:
Output: