array.pop javascript code example

Example 1: removing first item array js

var list = ["bar", "baz", "foo", "qux"];
list.shift()//["baz", "foo", "qux"]

Example 2: javascript remove last element from array

array.pop();   //returns popped element
//example
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.pop();  // fruits= ["Banana", "Orange", "Apple"];

Example 3: javascript remove last element from array

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

Example 4: how to remove last element in js

var array = [1, 2, 3, 4, 5, 6];
array.pop();
console.log(array);
//Output in console section:
//[1, 2, 3, 4, 5]

Example 5: js array pop

var array = ['A', 'B', 'C'];
// removes and returns last element
lastElement = array.pop();

Example 6: método pop javascript

const cars = ['Porsche', 'Ferrari', 'Mustang', 'Rolls Royce', 'Lamborghini'];

console.log(cars.pop());
// expected output: 'Lamborghini'

console.log(cars);
// expected output: Array ['Porsche', 'Ferrari', 'Mustang', 'Rolls Royce']