mdn array pop code example

Example 1: last element of an array javascript

var myArray = [1, 2, 3, 4];
myArray[myArray.length - 1];

Example 2: pop js

const plants = ['broccoli', 'cauliflower', 'cabbage', 'kale', 'tomato'];

console.log(plants.pop());
// expected output: "tomato"

console.log(plants);
// expected output: Array ["broccoli", "cauliflower", "cabbage", "kale"]

Example 3: javascript pop

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

Example 4: javascript array pop

let animals = ["dog","cat","tiger"];

animals.pop(); // ["dog","cat"]

animals.push("elephant"); // ["dog","cat","elephant"]

Example 5: js last array element

var linkElement = document.getElementById("BackButton");
var loc_array = document.location.href.split('/');
var newT = document.createTextNode(unescape(capWords(loc_array[loc_array.length-2]))); 
linkElement.appendChild(newT);

Example 6: js array.pop

let cats = ['Bob'];

cats.unshift('Willy'); // ['Willy', 'Bob']

cats.unshift('Puff', 'George'); // ['Puff', 'George', 'Willy', 'Bob']