Array.prototype.pop() by JavaScript convention.

let fruit = ['apple', 'orange', 'banana', 'tomato'];
let popped = fruit.pop();

console.log(popped); // "tomato"
console.log(fruit); // ["apple", "orange", "banana"]
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Answer from Stuart Kershaw on Stack Overflow
๐ŸŒ
Medium
medium.com โ€บ @iamdarius โ€บ 4-ways-to-remove-the-last-element-from-an-array-in-javascript-17749b12be0c
Learn 4 Ways to Remove the Last Element from an Array in JavaScript | by Darius Moore | Medium
September 8, 2022 - Below, the start count (the first parameter) is given an argument of -1, and the delete count (the second parameter), is 1. These two arguments indicate that the delete operation will begin at the last element of the array, and will only delete one item, respectively. One thing to note here is that the splice method returns an array of deleted elements. If there are no items deleted from the array, an empty array will be returned.
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ pop
Array.prototype.pop() - JavaScript - MDN Web Docs
In case you want the value of this to be the same, but return a new array with the last element removed, you can use arr.slice(0, -1) instead. The pop() method is generic. It only expects the this value to have a length property and integer-keyed properties. Although strings are also array-like, ...
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Array โ€บ splice
Array.prototype.splice() - JavaScript - MDN Web Docs
The splice() method of Array instances changes the contents of an array by removing or replacing existing elements and/or adding new elements in place. To create a new array with a segment removed and/or replaced without mutating the original array, use toSpliced().
๐ŸŒ
Jaketrent
jaketrent.com โ€บ post โ€บ remove-array-element-without-mutating
Remove an Array Element Without Mutation - Jake Trent
August 18, 2017 - To remove elements from an array in an immutable way, array copying is required. You need a new data structure because you cannot change the first -- that would be mutation.
๐ŸŒ
Bobby Hadz
bobbyhadz.com โ€บ blog โ€บ javascript-remove-last-element-from-array
Remove last or last N elements from an Array in JavaScript | bobbyhadz
Copied!const arr = ['a', 'b', 'c', 'd']; // โœ… Remove the last 3 elements from an array const withoutLast3 = arr.slice(0, -3); console.log(withoutLast3); // ๐Ÿ‘‰๏ธ [ 'a', 'b' ] The Array.slice() method doesn't mutate the original array, it ...
๐ŸŒ
freeCodeCamp
freecodecamp.org โ€บ news โ€บ how-to-remove-an-element-from-a-javascript-array-removing-a-specific-item-in-js
How to Remove an Element from a JavaScript Array โ€“ Removing a Specific Item in JS
August 31, 2022 - There are many different ways to do the same thing in JavaScript. In this article you have learned nine different methods to remove an element from an array. Six of them do not mutate the original array, and three of them do.
Find elsewhere
๐ŸŒ
Codegive
codegive.com โ€บ blog โ€บ js_remove_last_element.php
js Remove Last Element: Master Array Manipulation (2026) โ€“ Efficiency, Immutability & Beyond!
In JavaScript, the pop() method is the most direct and efficient way to remove the last element from an array, modifying the array in place and returning the removed element. Alternatively, slice() creates a new array without the last element, offering an immutable approach.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ how-to-splice-an-array-without-mutating-the-original-array
How to Splice an Array Without Mutating the Original Array? | GeeksforGeeks
November 19, 2024 - Here are the most effective ways to do this ยท The combination of slice() and concat() methods allows you to remove elements from an array without mutating the original by creating a new array.
๐ŸŒ
HackerNoon
hackernoon.com โ€บ how-to-remove-the-last-element-of-a-javascript-array
How to Remove the Last Element of a JavaScript Array | HackerNoon
November 6, 2022 - Finally, another way to accomplish this without changing the original array is to use slice (not to be confused with splice). slice() differs from both pop() and splice() in that, it makes a shallow copy of the original array. Removing the last element with slice looks like this:
๐ŸŒ
30 Seconds of Code
30secondsofcode.org โ€บ home โ€บ javascript โ€บ array โ€บ remove first or last n array elements
Remove the first or last n elements from a JavaScript array - 30 seconds of code
December 24, 2023 - Conversely, in order to remove n elements from the end of an array, you can use Array.prototype.slice() with a start index of 0 and a negative end index. This will return a new array with the last n elements removed.
๐ŸŒ
Fjolt
fjolt.com โ€บ article โ€บ javascript-remove-last-element-of-array
Removing the last element of an array in Javascript
November 6, 2022 - Finally, another way to accomplish this without changing the original array is to use slice (not to be confused with splice). slice() differs from both pop() and splice() in that it makes a shallow copy of the original array. Removing the last element with slice looks like this:
๐ŸŒ
DEV Community
dev.to โ€บ smpnjn โ€บ removing-the-last-element-of-an-array-in-javascript-7ga
Removing the last element of an array in Javascript - DEV Community
November 6, 2022 - Finally, another way to accomplish this without changing the original array is to use slice (not to be confused with splice). slice() differs from both pop() and splice() in that it makes a shallow copy of the original array. Removing the last element with slice looks like this:
๐ŸŒ
Techie Delight
techiedelight.com โ€บ home โ€บ java โ€บ remove last element from an array in javascript
Remove last element from an array in JavaScript | Techie Delight
July 7, 2026 - This post will discuss how to remove the last element from an array in JavaScript... The standard way to remove the last element from an array is with the `pop()` method. This method works by modifying the original array.