Filter by Tags

How to remove an element from an array in JavaScript ?

Votes

0

0 0

How can I remove an element from an array in javascript ?

Open E-School
Posted on : Fri, Jan 19, 2018
Views : 106
Comments

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Answers (1)


0

Javascript does not provide any direct method to remove an element from the array. If you wish to remove an element you have to first find the index of the element in the array and then use the splice function to remove that element from the array

var array = [1,2,3,4,5];

var indexOfElementToRemove = array.indexOf(4);

if(indexOfElementToRemove > -1)
array.splice(indexOfElementToRemove, 1);

This tutorial explains this concepts in more details

http://openeschool.com/tutorial/3238/how-do-i-remove-a-particular-element-from-an-array-in-javascript 

Ravinder Singh
Fri, Jan 19, 2018
Loading...
Comments

Edit Answer

Submit
This answer will permanently deleted. Do you really want to delete this Answer ?
To Add your Answer Please
LogIn | SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp