javascript remove last element in array code example

Example 1: 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 2: javascript pop

var cars = ['mazda', 'honda', 'tesla'];
var telsa=cars.pop(); //cars is now just mazda,honda

Example 3: javascript array remove last

// example (remove the last element in the array)
let yourArray = ["aaa", "bbb", "ccc", "ddd"];
yourArray.pop(); // yourArray = ["aaa", "bbb", "ccc"]

// syntax:
// <array-name>.pop();

Example 4: how to remove last element of array in javascript

let numbers = [1, 2, 3];
numbers.pop();

Example 5: how to remove the last element of an array in javascript

let cars = ['BMW', 'Benz', 'Audi'];

cars.pop(); // ['BMW', 'Benz']