

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to remove last array element in JavaScript and return it?
To remove last array element in JavaScript, use the pop() method. JavaScript array pop() method removes the last element from an array and returns that element.
Example
You can try to run the following code to remove last array element −
<html> <head> <title>JavaScript Array pop Method</title> </head> <body> <script> var numbers = [40, 70, 80, 100]; var element = numbers.pop(); document.write("element is : " + element ); var element = numbers.pop(); document.write("<br />element is : " + element ); </script> </body> </html>
Output
element is : 100 element is : 80
- Related Questions & Answers
- How to remove first array element in JavaScript and return it?
- First element and last element in a JavaScript array?
- How to get the last element in JavaScript array?
- How to remove the 0th indexed element in an array and return the rest of the elements in JavaScript?
- JavaScript Remove random item from array and then remove it from array until array is empty
- JavaScript code to print last element of an array
- How to remove array element in MongoDB?
- How to remove every Nth element from an array JavaScript?
- Remove element from array referencing spreaded array in JavaScript
- How to add an element in the last of a JavaScript array?
- How to remove element in a MongoDB array?
- Copy an element of a masked array to a standard Python scalar and return it
- Remove json element - JavaScript?
- How do I remove a particular element from an array in JavaScript
- Merge and remove duplicates in JavaScript Array
Advertisements