Now JavaScript Tutorial will guide us that
JavaScript arrays are one way of keeping a program more organized and
normalize. JavaScript Arrays allow us to do some
things that are difficult without them. Arrays are usually a group of the same
type variable that use an index number to distinguish them from each other. And suppose
we want to
write out 5 names of employees at Global Guide Line, and we use
JavaScript variables for each one of
our employee.
Then we need to define 5
JavaScript variables like the below code...
Suppose we have more then 1000 employees in an organization then either we
define 1000
JavaScript variables in our
JavaScript. No However, a better way may be to
use an JavaScript array. To define an array, we need to follow the following
steps.
Name_of_Array would be the name we want to give the JavaScript array variable, the number_of_elements
argument
is the number of indexes we want in JavaScript array to define. So, for our employee
names, we could write
<script type="text/javascript">
var employees= new
Array(10);
employees[0]="John";
employees[1]="Smith";
employees[2]="Haney";
employees[3]="Lara";
employees[4]="David";
//now displaying the array elements content using
JavaScript for loop
for (i = 0; i < employees.length; i++)
{
document.write(employees[i].bold() + "<br/>");
}
</script>