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>
18 Related pages
- Date and Time JavaScript
- Display Date, JavaScripts
- Display Date, JS
- External JavaScripts in HTML head
- JavaScript confirm OK and Cancel
- JavaScript Promise API
- JavaScript redirect to
- JavaScript toggle class
- JS alert in php
- JS Blinking Text
- JS Date
- JS display image preview on the form before submit
- JS image inside ul li
- JS Numeric Sort
- JS prevent form resubmission
- JS, pop( ) remove last element in the array
- JS, push() adds to the last element in the array
- Timeout JS