.pop() to remove element from the back and .shift() to remove element from the beginning

 1) .pop() to remove element from the end of the Array

// .pop() method to remove elements from the end of an Array

// 0 1 2 3
const f = ['a', 'b', 'c', 'd'];

const x = f.pop(); // 10 will get added in the beginning and older elements will shift to the right

console.log(f);

console.log(x); // x will contain the removed elements i.e, 'd'

==========================================================================================
TERMINAL:






2) .shift() to remove element from the beginning of the Array

// .shift() method to remove elements from the beginning of an Array

// 0 1 2 3
const f = ['a', 'b', 'c', 'd'];

const x = f.shift(); // 'a' will be removed from the beginning of the Array and the
older elements will get shifted to left index

console.log(f);

console.log(x); // x will contain the removed elements i.e, 'a'

==========================================================================================
TERMINAL:








Comments