Wednesday, August 6, 2014

add elements to array in javascript

<!DOCTYPE html>
<html>
<body>

<p>Click the button to add a new element to the array.</p>

<button onclick="myFunction()">Try it</button>

<p id="demo"></p>

<script>
var fruits = [];
document.getElementById("demo").innerHTML = fruits;

function myFunction() {
    fruits.push("Kiwi","Shekhar");
    document.getElementById("demo").innerHTML = fruits;
}
</script>

</body>
</html>
Click the button to add a new element to the array.

No comments:

Post a Comment