JavaScript array - Web Development
46 Views

JavaScript array

Using array we can store multiple values in a single javascript variable. The array is a special variable which can store more than one value lets see a small example .

Now three variables for three values but if we have 100 car brands then we have to write 100 variables for 100 values.  So to avoid this situation we use an array. Now see the syntax of the array.

Array elements are numbered and starts with zero

If you run this code your output would be SUZUKI Why ?? 0 , 1 ,2 This is indexing DUKATI is at 0 , YAMAHA is at 1 & SUZUKI is at 2

Output :-

JavaScript Arrays


Now see more example of array indexing

Ouput of code

How to use array value in html

using document.getElementByID().innerHTML we can print array value in html form or paragraph tag or div tag .

It will print Bebbo Randy & Webmi  .So below is output

JavaScript Arrays in html

How to change array elements

Changing array elements is very simple . Lets see one example

Ronic will replace student Woler as you can see the index of Woler is 1. Output of code

How to change elemets of array

How to append or extract elemetns from array

push() is used to append or add elemetns to your array

Output this code

How to append elements in array()




How to use loop in Array

Let see example of for loop

Output of this code

Lopping in array

Now see more example

Output of code

Leave a Reply

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