javascript pop item from array code example

Example 1: remove a particular element from array

var colors = ["red","blue","car","green"];
var carIndex = colors.indexOf("car");//get  "car" index
//remove car from the colors array
colors.splice(carIndex, 1); // colors = ["red","blue","green"]

Example 2: javascript remove last element from array

var colors = ["red","blue","green"];
colors.pop();

Example 3: take off element form end of array

const colors = ["Blue", "Green", "Red", "Yellow"];
colors.pop();

console.log(colors); // ["Blue", "Green", "Red"]