Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to remove an element from array in JavaScript

Freaking Awesome WordPress Hosting
117 views
asked Feb 26, 2017 by avibootz
edited Apr 6, 2017 by avibootz

2 Answers

0 votes
var array = [1, 2, 3, 4, 5];
var i = array.indexOf(3);

document.write(i + "<br />");

if (i > -1) {
    array.splice(i, 1);
}

document.write(array);
        

/*

run:

2
1,2,4,5 

*/

 





answered Feb 26, 2017 by avibootz
0 votes
var array = [1, 7, 8, 9];

value = 7    
    
array = array.filter(function(item) { 
    return item !== value
})

document.write(array);
   
 
/*
run:
 
1,8,9  
 
*/

 





answered Nov 18, 2017 by avibootz

Related questions

2 answers 72 views
1 answer 66 views
1 answer 45 views
1 answer 67 views
...