Working with an array always is an important thing in JavaScript. How to remove the last element from an array? Let’s go into detail now.
Remove the last element from an array
Solution 1: Use pop() method
Pop method will remove the last element in your array and return it. This method will change your origin array.
Syntax:
array.pop()
Example:
const anArray = ["Tony", "Tommy", "Alex", "Alexa", "Jimmy", "Anna"];
console.log(anArray.pop());
console.log(anArray);
Output:
Anna
[ 'Tony', 'Tommy', 'Alex', 'Alexa', 'Jimmy' ]
Solution 2: Use slice() method
As you know, changing the original array always is a bad practice with developers. With slice method will help you to return a new array that removes the last element, and you can catch that array by assign to a variable.
Syntax:
array.slice(start, end)
Parameters:
- Start: Position that you want to start to slice your array
- End: Position that you want to end slice your array
If you don’t pass anything to the parameter slice method will return an array like an origin array. This is also a way to create a clone of your array. And slice method also can get negative numbers. With a negative number, it will count start from the end of the array. For example, with “-1,” it will be the index of the last element of your array. And you can remove the last index of your array in this way:
Example:
const anArray = ["Tony", "Tommy", "Alex", "Alexa", "Jimmy", "Anna"];
const arrChanged = anArray.slice(0, -1);
console.log(anArray);
console.log(arrChanged);
Output:
["Tony", "Tommy", "Alex", "Alexa", "Jimmy", "Anna"]
[ 'Tony', 'Tommy', 'Alex', 'Alexa', 'Jimmy' ]
Solution 3: Use the splice method
Splice method will remove your element in your array or add a new element. This method will change your origin array. I recommend you combine it with the slice method your something to create a new array and work on it.
Syntax:
splice(start, amount , element , elementN)
Parameters:
- Start: Start the index position that you want to remove or insert a new element
- Amount: define how many elements you want to remove from the start index
- Element, elementN: element that you want to insert from the start index
Example:
const anArray = ["Tony", "Tommy", "Alex", "Alexa", "Jimmy", "Anna"];
const newArray = anArray.slice();
newArray.splice(-1, 1);
console.log(anArray);
console.log(newArray);
Output:
[ 'Tony', 'Tommy', 'Alex', 'Alexa', 'Jimmy', 'Anna' ]
[ 'Tony', 'Tommy', 'Alex', 'Alexa', 'Jimmy' ]
Summary
In this tutorial, I showed you some solutions to remove the last element from an array in Javascript. You can use slice(), splice(),pop() method to do it. There are a lot of ways to do it. I believe that you can find out more solutions to finish this work.
Maybe you are interested:
- Push multiple Values to an Array in JavaScript
- Get the Difference between Two Arrays in JavaScript
- How to convert a Set to an Array in JavaScript

Hello, guys! I hope that my knowledge in HTML, CSS, JavaScript, TypeScript, NodeJS, ReactJS, MongoDB, Python, MySQL, and npm computer languages may be of use to you. I’m Brent Johnson, a software developer.
Name of the university: HOU
Major: IT
Programming Languages: HTML, CSS, JavaScript, TypeScript, NodeJS, ReactJS, MongoDB, PyThon, MySQL, npm