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 - 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. ... With the length property, it is fairly straightforward to remove the last item.
Discussions

How to remove last word from string in JavaScript
Maybe not the most preferred method but splice the string using spaces, remove the last index on the returned array, then rejoin the array indexes back together . . . Or probably better way is to just use lastIndexOf string method for a space, and then create a substring from the beginning to that index . . . someString = someString.substring(0, someString.lastIndexOf(" ")) More on reddit.com
🌐 r/learnjavascript
3
0
December 13, 2021
How do I get the last two characters in a string?
Hi, so basically I want to use string.pop() but for the two last characters instead of just one. Is there an easy/elegant way to do that? Thanks in… More on reddit.com
🌐 r/rust
15
8
November 16, 2015
Replace last character in string
Just depends how complex you want to make it. You could technically do it all in the pipeline: 'East1','West2' | ForEach-Object { if ($_[-1] -eq '1') { ($_.substring(0,$_.length-1) + '2') } else { ($_.substring(0,$_.length-1) + '1') } } East2 West1 More on reddit.com
🌐 r/PowerShell
10
4
January 16, 2020
How to remove the trailing slash in a path?

I'd look into the filepath package. Clean will do this: example

edit: if what you're working with isn't a filepath and you don't want as many changes as filepath.Clean imposes, path.Clean also does this, according to its documentation.

More on reddit.com
🌐 r/golang
4
1
September 19, 2017
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-delete-last-occurrence-from-js-array
JavaScript - Delete last Occurrence from JS Array - GeeksforGeeks
July 11, 2025 - JavaScript · let a = [34, 24, ... arrays. To remove the last element from an array, you can use the spread operator along with array destructuring....
🌐
CoreUI
coreui.io › answers › how-to-remove-the-last-item-from-an-array-in-javascript
How to remove the last item from an array in JavaScript · CoreUI
May 12, 2026 - Use the pop() method to efficiently remove the last element from a JavaScript array and return the removed value.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › remove-last-character
How to Remove the Last Character from a String in JavaScript - Mastering JS
November 12, 2021 - To remove the last character from a string in JavaScript, you should use the slice() method. It takes two arguments: the start index and the end index.
🌐
CoreUI
coreui.io › blog › how-to-remove-the-last-character-from-a-string-in-javascript
How to Remove the Last Character from a String in JavaScript · CoreUI
June 23, 2024 - The slice() method is generally preferred due to its simplicity and support for negative indexing. The substring() and replace() methods provide alternative approaches that can be useful in different scenarios.
🌐
Delft Stack
delftstack.com › home › howto › javascript › remove last element from array in javascript
How to Remove Last Element From Array in JavaScript | Delft Stack
February 2, 2024 - The pop() function is the most straightforward way to achieve this. It removes the last element from an array and returns the deleted element. ... The slice() function creates a copy of the defined part selected from the start to the stop (the ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-program-to-remove-first-and-last-characters-from-a-string
JavaScript- Remove Last Characters from JS String - GeeksforGeeks
July 23, 2025 - To remove the last character, provide 0 as the starting index and the second-to-last index as the ending index. JavaScript · let str = "Hello GFG"; let res = str.substring(0, str.length - 1); console.log(res); Output ·
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-remove-last-element-from-array
Remove last or last N elements from an Array in JavaScript | bobbyhadz
To remove the last N elements from an array, call the Array.slice() method with a start index of 0 and an end index of -N.
🌐
W3Schools
w3schools.com › jsref › jsref_pop.asp
JavaScript Array pop() Method
The pop() method removes (pops) the last element of an array. The pop() method changes the original array. The pop() method returns the removed element. The Array push() Method · The Array shift() Method · The Array unshift() Method · array.pop() ...
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › pop
Array.prototype.pop() - JavaScript - MDN Web Docs
The pop() method removes the last element from an array and returns that value to the caller. If you call pop() on an empty array, it returns undefined. Array.prototype.shift() has similar behavior to pop(), but applied to the first element in an array.
🌐
Delft Stack
delftstack.com › home › howto › javascript › remove last character from javascript
How to Remove Last Character From String in JavaScript | Delft Stack
February 2, 2024 - The . is used to match a single character. Thus, the regular expression /.$/ can be used to get the last character from a string. After this, we replace it with '' i.e. blank, to remove it from the string.
🌐
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 - One of the most frequent operations we perform on an array is removing the last element. There are a few different ways to do this - but one of the most common is to use the pop() method.
🌐
Byby
byby.dev › js-remove-last-char
How to remove last character from string in JavaScript
The . within the regular expression represents any character, and the $ denotes the end of the string. So, .$ matches the last character in the string. By replacing it with an empty string, that character is removed.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Array › pop
JavaScript Array pop() - Remove Last Element | Vultr Docs
December 9, 2024 - The pop() method is a fundamental array operation in JavaScript, designed to remove the last element from an array.
🌐
Flavio Copes
flaviocopes.com › home › javascript › how to remove the last character of a string in javascript
How to remove the last character of a string in JavaScript
April 20, 2020 - Learn how to remove the last character of a string in JavaScript with the slice() method, passing 0 and -1, which returns a new unmodified string.
🌐
Favtutor
favtutor.com › articles › remove-last-character-from-string-javascript
Remove the Last Character from a String in JavaScript
January 3, 2024 - Let us look into various methods to remove the last character from the string: The slice() method in JavaScript is the easiest to remove the last character from a string in JavaScript. It takes two arguments – the start index and the end index.
🌐
Fjolt
fjolt.com › article › javascript-remove-last-element-of-array
Removing the last element of an array in Javascript
November 6, 2022 - One of the most frequent operations we perform on an array is removing the last element. There are a few different ways to do this - but one of the most common is to use the pop() method.
🌐
GoLinuxCloud
golinuxcloud.com › home › programming › javascript › remove last character from string in javascript
Remove last character from string in JS [5 Methods]
April 1, 2023 - slice(0, -1) is the cleanest way to remove the last character from a JavaScript string. ... You should see one line logging slice-last: golinuxclou. The start index 0 keeps the string from the beginning.
🌐
Medium
frontendinterviewquestions.medium.com › how-to-remove-last-character-from-string-in-javascript-dd4b264094f1
How to remove last character from string in JavaScript ? | by Pravin M | Medium
October 8, 2024 - It takes two arguments: the start index and the end index (not inclusive). By providing the appropriate indices, you can easily remove the last character. ... let originalString = "Hello, World!"; let newString = originalString.slice(0, -1); // Removes the last character console.log(newString); // Output: Hello, World