
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Removing an element from an Array in Javascript
Let’s consider two cases while removing elements from an array. First, we will see how we can remove an element from the end of the array and in next section we will see how we can remove elements from the start of the array and from a given position of the element.
Removing an element from the end of the array
This can be accomplished using the pop method. For example,
let veggies = ["Onion", "Raddish"]; veggies.pop(); console.log(veggies);
This will give the output −
["Onion"]
Removing an element from the start of the array
This can be accomplished using the unshift method. For example,
let veggies = ["Onion", "Raddish"]; veggies.shift(); console.log(veggies);
This will give the output −
["Raddish"]
Removing an element from a given position of the array
Sometimes you need to remove an element from a given position in an array. JavaScript gives the splice method to remove from a given index. It can be used as follows −
let veggies = ["Onion", "Raddish", "Broccoli"]; veggies.splice(0, 1); // Removes 1 element from index 0 console.log(veggies);
This will give the output −
["Raddish", "Broccoli"]
- Related Articles
- Removing an element from the end of the array in Javascript
- Removing an element from the start of the array in javascript
- Removing an element from a given position of the array in Javascript
- Removing an array element from a MongoDB collection
- Removing the odd occurrence of any number/element from an array in JavaScript
- Completely removing duplicate items from an array in JavaScript
- Removing consecutive duplicates from strings in an array using JavaScript
- Removing an array element from MongoDB collection using update() and $pull
- Removing identical entries from an array keeping its length same - JavaScript
- Removing duplicate elements from an array in PHP
- Removing Negatives from Array in JavaScript
- Adding an element in an array using Javascript
- Removing an element from C++ std::vector by index?
- Searching an element in Javascript Array
- Unique sort (removing duplicates and sorting an array) in JavaScript

Advertisements