πAdd or Remove Element
const month = ['January','February','March','April','May','June','July','August','September'];
// Add a new element to the end of the array
console.log(month.push('October'));
console.log(month);
/*
[
'January', 'February',
'March', 'April',
'May', 'June',
'July', 'August',
'September', 'October'
]
*/
// Add a new element to the start of the array
console.log(month.unshift('October'));
console.log(month);
/*
[
'October', 'January',
'February', 'March',
'April', 'May',
'June', 'July',
'August', 'September',
'October'
]
*/
// Delete element to the end of the array
console.log(month.pop());
console.log(month);
/*
[
'October', 'January',
'February', 'March',
'April', 'May',
'June', 'July',
'August', 'September'
]
*/
// Delete element to the end of the array
console.log(month.shift());
console.log(month);
/*
[
'January', 'February',
'March', 'April',
'May', 'June',
'July', 'August',
'September'
]
*/
Last updated