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 [email protected]
Laravel 5.6 - Multiple File Upload With dropzone.js
Many time you need in your laravel appli...Laravel Collection count and countBy Method Example
In this article, we will discuss about h...Django - How to Create Custom Login Page
Within this article we will look at how...How to convert html to pdf laravel 5.4
Today laravelcode share with you how to...React JS Axios File Upload Example
In this tutorial, we will provide you ex...