remove last element from array and return array javascript 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: js array delete last

array.pop()

Example 3: javascript delete second last element of array

arr.splice(arr.length - 2, 1);

Example 4: javascript pop last element from array

var fruits = ["Banana", "Orange", "Apple", "Mango"];

fruits.pop();

Example 5: remove last from array javascript

var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.write(fruits);
document.write("<br>");
fruits.pop();

document.write(fruits)

Example 6: take off element form end of array

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

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