Skip to content

How to Append Element to Array in JavaScript

How to Append Element to Array in JavaScript. How to initialise array in JavaScript and Append some elements using pop() method.

On this page

The push() method is used to add elements in JavaScript array. This tutorial will help you to initialize an array in JavaScript. After that append some more elements in Array using push() method in JavaScript.

Append Element to Array in JavaScript

First, create an array in JavaScript. For example, we are creating an array games with two elements “chess” and “football”.

Now append two more elements “tennis” an “pool” in games array using push() method. This method returns the number of element in array after adding new elements.

Finally you can print the elements of array using console.log() function. You can also check the number of elements by printing total variable value.

Working Example:

Below is the working example of initializing an Array in JavaScript. After that append some more elements in existing array. At the end print the array element to console.

Added above content in a html file and check access page in the browser. Now check the console of the browser, You will find the results as below screenshot.

Rahul

Rahul Kumar is the founder and chief editor of TecAdmin.net. A Red Hat Certified Engineer (RHCE), he has worked in IT since 2009, with hands-on experience in Linux system administration, DevOps, web hosting, cloud platforms and automation. He started TecAdmin in 2013 to share practical, step-by-step guides, and leads its editorial work with one aim: making technical learning clear and useful for sysadmins, developers and beginners alike.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top