Javascript examples for Array Operation:Array Element
Removing an element of an array with splice
<html> <head> <meta name="viewport" content="width=device-width"> </head> <body> <script> my =["1", "2", "3", "4", "5", "6"]; function removeFromArray(array, el) { var pos = array.indexOf(el);/*from w w w . ja v a2s . c o m*/ pos > -1 && array.splice(pos, 1); } removeFromArray(my, "2"); console.log(my); removeFromArray(my, "5"); console.log(my); </script> </body> </html>