Introduction to JavaScript Array Methods

Push Method in Arrays
const k = [1,2,3,4,5,6]
k.push(7);
console.log(k);
Output
[1, 2, 3, 4, 5, 6, 7]
Pop Method in Arrays
const k = [1,2,3,4,5,6]
k.pop()
console.log(k); 
Output
[1, 2, 3, 4, 5]
indexOf method in Arrays
const k = [1,2,3,4,5,6]
  console.log(k.indexOf(3)); 
Output
2
lastIndexOf method in Arrays
const k = [1,2,3,4,5,6]
let x = k.lastIndexOf(6)
console.log(x);
Output
5
Finding length of an Array
const k = [1,2,3,4,5,6]
let x = k.length
console.log(x);
Output
6
reverse method in Arrays
const k = [1,2,3,4,5,6]
k.reverse()
console.log(k);
Output
[6, 5, 4, 3, 2, 1]
shift method in Arrays
const k = [1,2,3,4,5,6]
let x = k.shift()
console.log(x);
Output
1
slice method in Arrays
const k = [1,2,3,4,5,6]
        const j = k.slice(1,3)
        console.log(j);
Output
[2, 3]

//only starting index for slice
const k = [1,2,4,3,5,6]
console.log(k.slice(1));//will slice from index 2 to 6
Output
[2, 4, 3, 5, 6]
sort method in Arrays
const k = [1,2,4,3,5,6]
          k.sort()
          console.log(k);
Output
[1, 2, 3, 4, 5, 6]
splice method in Arrays
const k = [1,2,4,3,5,6]
k.splice(2,2) //removes 2 elements from index 2
console.log(k);
Output
[1, 2, 5, 6]
//0 here represents remove none
const k = [1,2,4,3,5,6]
k.splice(2,0,88,99) //add two elements at index 2
console.log(k);
Output
[1, 2, 88, 99, 4, 3, 5, 6]
//splice for add and remove elements 
//remove 2 elements and add two elements at index 2
const k = [1,2,4,3,5,6]
k.splice(2,2,88,99) //removes 2 elements and adds two elements at index 2
console.log(k);
Output
[1, 2, 88, 99, 5, 6]
toString method in Arrays
const k = [1,2,4,3,5,6]
console.log(k.toString());
console.log(k.length);
Output
6