Click the button to add elements to the array - Javascript Array Operation

Javascript examples for Array Operation:Array Element

Description

Click the button to add elements to the array

Demo Code

ResultView the demo in separate window

<html>
   <head></head>
   <body> 
      <p>Click the button to add elements to the array.</p> 
      <button onclick="myFunction(3)">Try it</button> 
      <p id="demo"></p> 
      <script>
var fruits = ["Banana", "Orange", "Apple", "Mango"]
document.getElementById("demo").innerHTML = fruits;
function myFunction(index) {//from   ww  w.  j  a  va2 s.  c om
    console.log(index)
    fruits.splice(index, 1);
    document.getElementById("demo").innerHTML = fruits;
}

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

Related Tutorials