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"]
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"]
2 of 16
762
Use splice(startPosition, deleteCount)
array.splice(-1)
var array = ['abc','def','ghi','123'];
var removed = array.splice(-1); //last item
console.log( 'array:', array );
console.log( 'removed:', removed );
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › splice
Array.prototype.splice() - JavaScript | MDN
Although strings are also array-like, this method is not suitable to be applied on them, as strings are immutable. js · const myFish = ["angel", "clown", "mandarin", "sturgeon"]; const removed = myFish.splice(2, 0, "drum"); // myFish is ["angel", "clown", "drum", "mandarin", "sturgeon"] // removed is [], no elements removed ·
Videos
02:17
How to remove the last element of a JavaScript Array - Array.p...
02:23
how to remove the last element from an array in javascript - YouTube
03:55
How to Remove First and Last Element From Array in JavaScript - ...
JavaScript Remove Last Element From Array | HowToCodeSchool.com ...
Remove the Last Element from an Array in JavaScript | Coding ...
03:34
How to Add and Remove Elements in Array in Javascript - YouTube
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › pop
Array.prototype.pop() - JavaScript | MDN
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, ...
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 - Splice is a powerful method that can be used to add new elements to an array, remove elements from an array, or perform both actions simultaneously. Unlike slice, splice mutates the original array that it is being invoked on. 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.
Jaketrent
jaketrent.com › post › remove-array-element-without-mutating
Remove an Array Element Without Mutation
We could simply do that: create a new array (a clone of the original) and mutate that instead of the original. To do this, we could use a clone function or the spread operator (...) to copy the original array into a whole new array, the splice just the new array.
GitHub
github.com › kolodny › immutability-helper › issues › 78
how to use immutability-helper remove elements from array · Issue #78 · kolodny/immutability-helper
September 26, 2017 - var state = [{name:'a'},{name:'b'},{name:'c'},{name:'d'}]; var indexToRemove = state.findIndex(item => item.name === 'c'); var newState = update(state, {$splice: [[indexToRemove, 1]]}); console.log(newState); // [{name: "a"}, {name: "b"}, {name: "d"}]``` if i have a list var list=['a','c'], how to remove two elements from array 'state'
Published Dec 18, 2017
Agney
agney.dev › blog › immutable-array-operations
Immutable Array Operations - JavaScript | Blog
October 5, 2019 - Adds one or more elements to the beginning of an array and returns the new length of the array. ... removes the last element from an array and returns that element.
Top answer 1 of 6
42
You can use Array#filter.
return state.set('things', state.get('things').filter(o => o.get('id') !== 'a1'));
2 of 6
15
When you are using filter it iterates all cycle -> one effective way is finding index => slice and using splitter ...
const index = state.findIndex(data => data.id === action.id);
return [...state.slice(0, index), ...state.slice(index + 1)];
Ultimate Courses
ultimatecourses.com › blog › remove-specific-item-from-array-javascript
Removing Items from an Array in JavaScript - Ultimate Courses
Array.prototype.indexOf() will return -1 if the element is not found so I’d recommend a safety check around this. You’ll notice I’ve also added const removedDrink. This is because .splice() returns us the removed item(s): // ["Coffee"] console.log(removedDrink); // ["Cola", "Lemonade", "Water"] console.log(drinks); ... So now we understand a little more about mutable and immutable, let’s uncover the immutable pattern to “remove” an element from an array.
W3Schools
w3schools.com › jsref › jsref_pop.asp
JavaScript Array pop() Method
cssText getPropertyPriority() getPropertyValue() item() length parentRule removeProperty() setProperty() JS Conversion · ❮ Previous JavaScript Array Reference Next ❯ · Remove (pop) the last element: const fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.pop(); Try it Yourself » ·
Top answer 1 of 16
161
Copyfruits.shift(); // Removes the first element from an array and returns only that element.
fruits.pop(); // Removes the last element from an array and returns only that element.
See all methods for an Array.
2 of 16
116
Creates a 1 level deep copy.
Copyfruits.slice(1, -1)
Let go of the original array.
Thanks to @Tim for pointing out the spelling errata.
Tutorial Reference
tutorialreference.com › javascript › examples › faq › javascript-how-to-remove-last-element-from-array
How to Remove the Last Element from an Array in JavaScript | Tutorial Reference
Non-mutating (Immutable): Creates a new array with the desired changes. The original array is left untouched. This is the recommended best practice in modern JavaScript as it leads to more predictable and less error-prone code. Mutating: Modifies the original array in place.
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-delete-last-occurrence-from-js-array
JavaScript - Delete last Occurrence from JS Array - GeeksforGeeks
July 11, 2025 - The array length property in JavaScript ... arrays. To remove the last element from an array, you can use the spread operator along with array destructuring....
TutorialsPoint
tutorialspoint.com › how-to-remove-last-array-element-in-javascript-and-return-it
How to remove last array element in JavaScript and return it?
We have learned two methods, using which we can remove the last array element in JavaScript. Among these methods, pop() is the easiest way to remove the last element of an array.