Adding elements to array ( push() & arr[arr.length] )

 1) Two methods to add elements in an array


// Adding array elements
// 0 1 2 3 4
const fruits = ['Mango', 'Orange', 'Banana', 'Grapes', 'Pineapple'];

// 1st by push method

fruits.push('Lemon'); // push will add/push the elements at the end of the array

console.log(fruits);

// 2nd by arr.length method

fruits[fruits.length] = 'Lemon'; // fruits[5]

console.log(fruits);

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








Comments