SQL PHP HTML ASP JavaScript articles and free scripts to download
JavaScript Tutorials
Popular Tutorials
Drop down list
Timer function
JavaScript Tutorials
String
Array
Date & Time
Form Validation
Event Handling
Math Functions
JavaScript Forum
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

 
 

Displaying all elements of an array

We can display all elements of an array by looping through each element of the array. Here we will increment the index of the array by one in each loop and display elements of the array one by one. To identify how many loops we have to make we must know the total number of elements present inside the array. That we can find out like this

array_name.length


So this number we will set as upper limit of our number of rotation or looping. You can check our tutorial on creating array to create an array and now we will try to display each element of the array. Here is the code.

var scripts = new Array();
scripts[0] = "PHP";
scripts[1] = "ASP";
scripts[2] = "JavaScript";
scripts[3] = "HTML";


for (i=0;i<scripts.length;i++)
{
document.write(scripts[i] + "<br >");
}


The for loop in the above code loops through the elements of the array and display one by one vertically by adding one line break at the end of each element. The upper limit of the for loop is set to script.length value which is in this case equal to 4

Displaying elements of an array by using join method
Further readings
Declaring array in JavaScript
Displaying elements of an array by looping through
join():Displaying elements of an array using join() function
sort():Sorting of elements of an array using function
length:Length property to get the total number of elements in an array
reverse():Reversing the elements of an array
pop():Removeing last element of an array by using pop()
shift():Removeing first element of an array using shift()
push():Adding elements to array using push()
unshift():Adding elements to array using unshift()
splice():Add replace remove elements from an array using splice()
split():Creating array by splitting string variable
 
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.

Scripts
PHP
JavaScript