H I O X INDIA
Javascript Tutorial
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

Java-Script Tutorial
Introduction
Variables
Operators
Statements
Loops
Functions
Objects
Arrays
Browser Objects
Form DOM
Ask Your Doubts
Feedback





Javascript Array


Topic

How to create an array with out specifying any length?
or
What are dense arrays and how can we use them?



Explanation

Dynamic Arrays:
       In many a cases we will not want to create the array with a fixed size or length. In such cases we can create an array with out passing length. This array will dynamically set its value as and when a new variable or entry is added.

Syntax:
       var araay = new Array();

Now we can assign value at any position in this array as it has no length limit. We can test this by using the attribute "length".
e.g:
       varname[6] = "testing array";

As we have assigned a value at 6th position the length of array will now be 7.
Example Code:
<script language="javascript">
var araay = new Array();
araay[6] = "testing array";
document.write("Size of dynamic array is - "+araay.length);
</script>


Result:


Dense Array:
        Dense array is nothing different in functionality from a normal array. The only difference is that the values are assigned to the array at the time of initialization of the array.
E.g: var arraa = new Array("index 0","index 1","index 2");

Example Code:
<script language="javascript">
var arraa = new Array("array test 1","array test 2");
document.write("Result from dense array is - "+arraa[1]);
</script>


Result:

In the next chapter we will look into the predefined methods of Array object ..


        Javascript (JS) is one of the most used languages in the world. Some times spelled as Java Script. Hope you enjoy this tutorial. Do send your feedback or suggestions on this javascript or java script tutorial. This is a copyright content.

others

privacy policy     license     sitemap
© 2004-2005 HIOX INDIA - hioxindia.com

Other Links