Javascrip new Array
Create an array
There are several different ways to create an array. Creates an array of arrays to participate in () construct the old way.
JavaScript arrays are dynamic, and you can declare an array without constructing the array parameters ().
In this case, you will create an empty array with no elements.
Select Actionselect alltry it<script type= "Text/javascript Tutorial" >
We initialize the array using the array () constructor.
var first_array = new Array ();
First_array[0] = "This is a element";
FIRST_ARRAY[1] = 5;
FIRST_ARRAY[2] = "javascript-tutorial";
FIRST_ARRAY[3] = 16;
FIRST_ARRAY[4] = 7;
var counter=0;
Let's print out the elements of the array.
for (counter=0; counter<first_array.length; counter++)
document.write (First_array[counter] + "<br>");
</script>
Select Actionselect alltry it<script type= "Text/javascript" >
We declare the "a" single integer as a argument.
var cars = new Array (5);
Cars[0] = "Audi";
CARS[1] = "Bentley";
CARS[2] = "Mercedes";
CARS[3] = "Mini";
CARS[4] = "BMW";
Now we are declare the second array and pass 8 arguments.
This technique does isn't work in JavaScript 1.2.
var flowers = new Array ("Rose", 2.45, "Daisy", 1.57, "Orchild", 0.75,
"Tulip", 1.15);
var counter=0;
document.write ("
for (counter=0; counter<cars.length; counter++)
document.write (Cars[counter] + "<br>");
counter=0;
document.write ("
For (counter=0 counter<flowers.length; counter++) {
if (counter% 2 = 0) {
document.write (Flowers[counter] + "costs");
}
else {
document.write (Flowers[counter] + "<br>");
}
}
</script>