How to remove an item from JavaScript array by value?

JavascriptWeb DevelopmentFront End Technology

To remove an item from an array in JavaScript, firstly get the item and then remove it using the splice() method. You can try to run the following code −

Example

Live Demo

<html>    
   <body>              
      <script>  
         var array = [10, 30, 40, 80, 90];        
         var index = array.indexOf(90);                
         document.write("Original array: "+array);  
         if (index > -1) {          
            array.splice(index, 1);        
         }  
         document.write("<br>New array after deletion: "+array);  
      </script>          
   </body>
</html>

Output

Original array: 10,30,40,80,90
New array after deletion: 10,30,40,80
raja
Published on 18-Feb-2018 11:13:25
Advertisements