javascript-tutorialsmade

Add values & Loop through array in JavaScript

In this post you are going to learn how to create an array variable and push values into that array in JavaScript.

How to create an array in JavaScript?

It’s very simple, created a variable name and add [] (square brackets) beside to it.

for eg:

 So, to add values into the array, is there any default function available in JavaScript? if yes then how to add it?

Yes, push() is the default method available in JavaScript.  To add a value in the array see below example:

the above example will add a value ‘myvalue’ into the array ‘arr’.

Do you have any JavaScript example explaining how to add values into an array and loop through the array?

Yes, here is the script:

Read the comments in the above script to understand step by step.

If you want to see the demo, please click the below link:

demo

Related Posts

Leave a Reply