.push() to add element at back and .unshift() to add element in the beginning

 1) .push() method to add element at the end of an Array

// .push() method to add elements at the end of an Array

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

const x = f.push(10);

console.log(f);

console.log(x); // x will contain the new length of the Array i.e , 5

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










2) .unshift() method to add element in the beginning of an Array

// .unshift() method to add elements in the beginning of an Array

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

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

console.log(f);

console.log(x); // x will contain the new length of the Array i.e , 5

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







Comments