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 Top answer 1 of 16
1055
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
2 of 16
762
Use splice(startPosition, deleteCount)
array.splice(-1)
Show code snippet
var array = ['abc','def','ghi','123'];
var removed = array.splice(-1); //last item
console.log( 'array:', array );
console.log( 'removed:', removed );
Run code snippetEdit code snippet Hide Results Copy to answer Expand
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
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
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
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.
03:03
How to Remove the Last 2,3,4,N Elements from an Array in JavaScript ...
02:11
How to Remove the Last 2,3,4, N Characters from a String in ...
03:30
How to Remove the Last Character from a String in JavaScript - YouTube
03:41
Codewars - Javascript - Remove First and Last Character Part Two ...
02:49
Codewars - Javascript - Remove First and Last Character - YouTube
02:17
How to remove the last element of a JavaScript Array - Array.p...
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.
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 ·
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.
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