February 5, 2022
For the purpose of creating an array, we can initialize it with values. Also, we can use the Array() constructor. The following examples demonstrate how to create arrays.
var a1=[2, 5, 9, 8, 4, 10]; var a2=[12, 18, 'abc', 90.8, 1, 2, 'hello']; var a3=Array(6,1,3); var a4=Array(10);
concat(): This method helps us in combining two or more arrays to create a single large array.
join(): In order to join the elements of an array by using a separator, we use the join method.
push(): Basically, this method inserts an element at the last position in an array.
pop(): Similarly, the pop() method displays the last element from the array and removes it.
reverse(): In order to reverse the elements in an array we use the reverse() method.
sort(): Likewise, the sort() method sorts the elements of an array in ascending order.
indexOf() method returns the index of the first occurrence of the specified element in the array. In case, the element is not there, it returns -1.
Likewise, the lastIndexOf() method starts searching the array starting from the last element and searches backward. In case, the element is not there, it returns -1.