Removing an array element using splice() method - Javascript Array

Javascript examples for Array:splice

Description

Removing an array element using splice() method

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
    window.onload=function(){/* w  w w.j a  v a2  s  .  c  o  m*/
var arr = ["copper", "oil", "silver", "bronze", "gold", "iron"];
for (var i = 0; i < arr.length; i++) {
    if (arr[i].indexOf('l') !== -1) {
        arr.splice(i, 1);
        i = i - 1;
    }
}
console.log(arr)
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials