ZaZaKi, a web developer Between Manchester UK & Rotterdam NL. © 2015-2024.

JS, push() adds to the last element in the array

push() adds to the last element in the array


<!DOCTYPE html>
<html>
<body>

<p id="demo1"></p>
<p>Now dogs added the animals</p>
<p id="demo2"></p>

<script>

// array
var animals = ['pigs', 'goats', 'sheep'];

// it will display pigs, goats and sheep
document.getElementById("demo1").innerHTML = animals;

// adds dogs
animals.push('dogs');

// it will display pigs, goats, sheep and dogs
document.getElementById("demo2").innerHTML = animals;

</script>

</body>
</html>

Categroy:
back-end , javascripts