push()
MethodYou can simply use the JavaScript push()
method to append values to an array.
The following example will show you how to append single or multiple values to an array in JavaScript.
<script>
var persons = ["Harry", "John", "Clark"];
// Append a single value to persons array
persons.push("Peter");
console.log(persons);
// Prints: ["Harry", "John", "Clark", "Peter"]
// Append multiple values to persons array
persons.push("Rohn", "Alice");
console.log(persons);
// Prints: ["Harry", "John", "Clark", "Peter", "Rohn", "Alice"]
// Loop through persons array and display all the values
for(var i = 0; i < persons.length; i++){
document.write("<p>" + persons[i] + "</p>");
}
</script>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on harsukh21@gmail.com
How to increase automatic logout time in phpMyAdmin
phpMyAdmin is open-source web based appl...Node.js MySQL Create table into Database Server
This article will guide you to how to cr...How to Redirect to Different URLs with .htaccess file
Apache is the first layer of your websit...How to Insert and fetch fullcalendar events from mysql database ?
Hello to all, welcome to therichpost.com...Laravel 8 Paypal Payment Gateway Integration
Paypal is a international payment proces...