How to Remove Last Element from an Array in JavaScript? 5 Ways

Are you thrilled to know the different ways to remove the last element from an array in JavaScript?

Discover five (5) different ways to remove the last element from an array.

This article covers all the methods you need to know. From using the pop() method to manipulating the length property.

Aside from that, you’ll also learn how to remove the last two (2) or multiple elements from an array in JavaScript.

JavaScript remove last element from array

Here are 5 different ways to remove the last element from an array in JavaScript:

Using the pop() method

The pop() method removes the last element from an array and returns that element. This method changes the length of the array.

Here’s an example:


let subjects = ["Software Engineering", "Math", "Programming", "Web Development", "Software Development"];
let lastElement = subjects.pop(); ✅
console.log(subjects);

Output:

[ 'Software Engineering', 'Math', 'Programming', 'Web Development' ]

Using the splice() method

The splice() method can be used to alter the contents of an array by removing, replacing, or adding elements.

To remove the last element of an array, you can call splice(-1, 1) on the array.

Here’s an example:

let subjects = ["Software Engineering", "Software Development", "Programming", "Web Development", "Math"];
subjects.splice(-1, 1); 
console.log(subjects); 

Output:

[
  'Software Engineering',
  'Software Development',
  'Programming',
  'Web Development'
]

Using the slice() method

The slice() method creates a new array object that contains a shallow copy of a portion of an existing array.

The portion is specified by the start and end indices, where the start index is included and the end index is not.

To remove the last element, you can use slice(0, -1).

Here’s an example:

let subjects = ["Software Engineering", "Math", "Software Development", "Web Development", "Programming"];
subjects = subjects.slice(0, -1); 
console.log(subjects);

Output:

[
  'Software Engineering',
  'Math',
  'Software Development',
  'Web Development'
]

Using the length property

You can also remove the last element from an array by setting its length property to one less than its current value.

Here’s an example:

let subjects = ["Software Development", "Math", "Programming", "Web Development", "Software Engineering"];
subjects.length -= 1; 
console.log(subjects); 

Output:

[ 'Software Development', 'Math', 'Programming', 'Web Development' ]

Using the delete operator

The delete operator is used to cut or remove a property from an object. You can use it to remove the last element from an array by deleting the property at the index of the last element.

let subjects = ["Software Engineering", "Math", "Programming", "Software Development", "Web Development"];
delete subjects[subjects.length - 1]; 
console.log(subjects);

Output:

[
  'Software Engineering',
  'Math',
  'Programming',
  'Software Development',
  <1 empty item>
]

When you use it to remove the last element from an array by deleting the property at the index of the last element, it leaves an empty slot in the array.

This is why the output shows <1 empty item> at the end of the array.

If you want to remove the last element from an array without leaving an empty slot, you can use one of the other methods which we mentioned earlier, such as pop(), splice(), slice(), or setting the length property to one less than its current value.

How to remove last 2 or 3 element from array in JavaScript?

The following are a few ways to remove the last 3 elements from an array in JavaScript.

To remove the last 3 elements, you can use splice(-3, 3)

Here’s an example:

let subjects = ["Software Engineering", "Math", "Programming", "Web Development", "Software Development"];
subjects.splice(-2,2 ); ✅
console.log(subjects); 

Output:

[ 'Software Engineering', 'Math', 'Programming' ]

Here’s another example:

let subjects = ["Software Engineering", "Math", "Programming", "Web Development", "Software Development"];
subjects.splice(-3, 3); 
console.log(subjects); 

Output:

[ 'Software Engineering', 'Math' ]

To remove the last 3 elements, you can use slice(0, -3)

Here’s an example:

let subjects = ["Web Development", "Software Development", "Software Engineering", "Math", "Programming"];
subjects = subjects.slice(0, -3); 
console.log(subjects); 

Output:

[ 'Web Development', 'Software Development' ]

You can also remove the last 3 elements from an array by setting its length property to three less than its current value

Here’s an example:

let subjects = ["Programming", "Web Development", "Software Engineering","Software Development", "Math"];
subjects.length -= 3; 

console.log(subjects); 

Output:

[ 'Programming', 'Web Development' ]

How to remove 1st and last element in array JavaScript?

Here are the 3 different ways to remove the first and last elements from an array in JavaScript.

Using the shift() and pop() methods

The shift() method is used to remove and return the first element of an array.

The pop() method removes the last element from an array and returns that element. You can use both methods to remove the first and last elements from an array.

Here’s an example:

let subjects = ["Software Engineering", "Math", "Programming", "Web Development", "Software Development"];
let firstElement = subjects.shift(); ✅
let lastElement = subjects.pop(); 
console.log(subjects); 

Output:

[ 'Math', 'Programming', 'Web Development' ]

Using the splice() method

To remove the first and last elements, you can use splice(0, 1) to remove the first element and splice(-1, 1) to remove the last element.

Here’s an example:

let subjects = ["Programming", "Web Development", "Software Development", "Math", "Software Engineering"];
subjects.splice(0, 1); 
subjects.splice(-1, 1); 
console.log(subjects);

Output:

[ 'Web Development', 'Software Development', 'Math' ]

Using the slice() method

To remove the first and last elements, you can use slice(1, -1).

Here’s an example:

let subjects = [ "Math", "Programming", "Web Development", "Software Development", "Software Engineering"];
subjects = subjects.slice(1, -1); 
console.log(subjects);

Output:

[ 'Programming', 'Web Development', 'Software Development' ]

Conclusion

In conclusion, there are several ways to remove the last element from an array in JavaScript.

This article has covered five different methods, including using the pop(), splice(), slice(), and delete methods, as well as manipulating the length property.

Additionally, you can also use these methods to remove multiple elements from the end of an array.

We are hoping that this article provides you with enough information that help you understand the JavaScript remove last element from array.

If you want to dive into more JavaScript topics, check out the following articles:

Thank you for reading Itsourcecoders 😊.

Quick step-by-step summary (click to expand)
  1. JavaScript remove last element from array. Read the ‘JavaScript remove last element from array’ section for the details and code.
  2. How to remove last 2 or 3 element from array in JavaScript. Read the ‘How to remove last 2 or 3 element from array in JavaScript?’ section for the details and code.
  3. How to remove 1st and last element in array JavaScript. Read the ‘How to remove 1st and last element in array JavaScript?’ section for the details and code.
  4. Conclusion. Read the ‘Conclusion’ section for the details and code.

Frequently Asked Questions

Is JavaScript still worth learning in 2026?
Yes. JavaScript runs on 98% of websites for the front-end, dominates the back-end via Node.js, powers mobile apps through React Native, builds desktop tools through Electron, and is the scripting layer for most AI tooling (LangChain.js, OpenAI SDK, Vercel AI). Whether you target web, mobile, AI, or full-stack capstones, JavaScript is the broadest single language you can learn.
What is the difference between var, let, and const?
var is function-scoped, hoisted to the top of its scope, and can be redeclared, which leads to bugs in modern code. let is block-scoped (only visible inside the nearest {}) and can be reassigned. const is block-scoped and cannot be reassigned, although object contents can still mutate. Default to const for everything, switch to let only when you actually need to reassign, and avoid var in any code written after 2017.
Which JavaScript version should I target in 2026?
Target ES2020 (ES11) as the safe baseline because every modern browser and Node.js 14+ supports it fully. ES2022 adds useful features like top-level await, private class fields with the # prefix, and the .at() array method. If you are writing for older browsers (IE11 or older Android WebViews), transpile down with Babel or use a build tool like Vite, esbuild, or webpack.
What is the best free editor for JavaScript?
Visual Studio Code is the industry standard, free, with built-in IntelliSense, debugger, terminal, Git, and a huge extension marketplace (ESLint, Prettier, GitHub Copilot, Tailwind). Install the JavaScript and TypeScript Nightly extension for the latest language features. JetBrains WebStorm is more powerful and free for students with a verified .edu email. For quick scratchpad work, the Chrome DevTools Sources panel includes a workspace and breakpoint debugger.
How do I run JavaScript locally vs in the browser?
In the browser: open DevTools with F12 (or right-click then Inspect), go to the Console tab, type or paste your code, press Enter. For HTML pages, add a script tag pointing to your .js file. Locally with Node.js: download Node from nodejs.org (LTS version), then run node script.js in your terminal from the file folder. Use the same Node setup for backend capstones, API integrations, and scripts that do not need a browser.
What can I build with JavaScript for my BSIT capstone?
Common BSIT capstones in JavaScript: full-stack web apps using React or Vue on the front-end with Node.js and Express on the back-end (MongoDB or MySQL for the database), real-time chat or notification systems using Socket.io, single-page dashboards with Chart.js or D3.js, cross-platform mobile apps with React Native, AI-powered chatbots using OpenAI SDK and LangChain.js, and Chrome extensions for productivity tools. Add Tailwind CSS for the UI and Vercel or Netlify for free deployment.

Caren Bautista


Technical Writer at PIES IT Solution

Responsible for crafting clear, well-structured, and beginner-friendly content across the platform. Handles the writing, proofreading, and editorial review of tutorials, guides, and documentation to ensure every article is accurate, readable, and easy to follow.

Expertise: Technical Writing · Content Creation · Documentation · Editorial Writing · JavaScript · TypeScript · Python · Python Errors · HTTP Errors · MS Excel
 · View all posts by Caren Bautista →

Leave a Comment