- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 do I remove a particular element from an array in JavaScript
To remove an element from an array, use the splice() method. JavaScript array splice() method changes the content of an array, adding new elements while removing old elements.
The following are the parameters −
index − Index at which to start changing the array.
howMany − An integer indicating the number of old array elements to remove. If howMany is a 0, then no elements are removed.
element1, ..., elementN − The elements adds to the array. If you don't specify any elements, splice simply removes the elements from the array.
You can try to run the following code to learn how to add and remove individual elements in a JavaScript array −
Example
Live Demo<html> <head> <title>JavaScript Array splice Method</title> </head> <body> <script> var arr = ["orange", "mango", "banana", "sugar", "tea"]; var removed = arr.splice(2, 0, "water"); document.write("After adding 1: " + arr ); document.write("<br />removed is: " + removed); removed = arr.splice(3, 1); document.write("<br />After adding 1: " + arr ); document.write("<br />removed is: " + removed); </script> </body> </html>
Output
After adding 1: orange,mango,water,banana,sugar,tea removed is: After adding 1: orange,mango,water,sugar,tea removed is: banana
- Related Articles
- How do I remove a string from an array in a MongoDB document?
- How to remove every Nth element from an array JavaScript?
- How can I remove a specific item from an array JavaScript?
- How can I remove a specific item from an array in JavaScript
- How do I recursively remove consecutive duplicate elements from an array?
- How do I make an array with unique elements (remove duplicates) - JavaScript?
- How do I remove a property from a JavaScript object?
- How to remove an element from an array in Java
- Remove element from array referencing spreaded array in JavaScript
- How to delete/remove an element from a C# array?
- How do I empty an array in JavaScript?
- How to remove an element from Array List in C#?
- How to get a particular element from MongoDB array?
- How do you remove an array element by its index in MongoDB
- How to remove a class name from an element with JavaScript?

Advertisements