How to remove specific element from an array in JavaScript

2 Answers

0 votes
const arr = ['javascript', 'php', 'python', 'c', 'c++'];

arr.splice(2, 1); 

console.log(arr); 
  
  
    
      
      
/*
run:
      
["javascript", "php", "c", "c++"]
      
*/

 



answered Jun 16, 2021 by avibootz
0 votes
const arr = ['javascript', 'php', 'python', 'c', 'c++'];
 
const index = arr.indexOf('python');

if (index !== -1) {  
	arr.splice(index, 1);
}
 
console.log(arr); 
   
   
     
       
       
/*
run:
       
["javascript", "php", "c", "c++"]
       
*/

 



answered Jun 16, 2021 by avibootz
edited Jul 4, 2022 by avibootz

Related questions

1 answer 166 views
1 answer 133 views
2 answers 214 views
1 answer 175 views
...