Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
141
rated 0 times [  148] [ 7]  / answers: 1 / hits: 31796  / 13 Years ago, thu, april 28, 2011, 12:00:00

I have an array with name ids and some values like ['0','567','956','0','34']. Now I need to remove 0 values from this array.
ids.remove (0); is not working.


More From » arrays

 Answers
78

Use splice method in javascript. Try this function:



function removeElement(arrayName,arrayElement)
{
for(var i=0; i<arrayName.length;i++ )
{
if(arrayName[i]==arrayElement)
arrayName.splice(i,1);
}
}


Parameters are:



arrayName:-      Name of the array.
arrayElement:- Element you want to remove from array

[#92508] Wednesday, April 27, 2011, 13 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
gabriel

Total Points: 323
Total Questions: 107
Total Answers: 108

Location: Federated States of Micronesia
Member since Sun, May 16, 2021
3 Years ago
;