CRUD operation in Array - Java Script

 push() :

----------

>add one or more element at the end of the array

>return new length of an array

const animal = ['pig','lion','tiger']
animal.push("ant","cow","cat")
console.log(animal);


unshift():

-------------

>add one or more element at the START of the array

>return new length of an array

const animal = ['pig','lion','tiger']
animal.unshift("ant","cow","cat")
console.log(animal);


pop():

---------

>remove last element from the array

>changes length of the array

const animal = ['pig','lion','tiger','ant','cow','cat']

console.log(animal);
console.log(animal.pop());
console.log(animal);


shift():

------------

>remove FIRST element from the array

>changes length of the array

const animal = ['pig','lion','tiger','ant','cow','cat']

console.log(animal);
console.log(animal.shift());
console.log(animal);




0 Comments