Results 1 to 6 of 6

Thread: How an Array Class is Used in Javascript?

  1. #1
    Join Date
    Jul 2006
    Posts
    128

    How an Array Class is Used in Javascript?

    Hi friends,
    I have newbie to the JavaScript. Before that I have done C and C++ programming language. Also I am little knowledge of Java and Visual Basic since I was having that subjects in my college. Recently I have started doing the JavaScript. I don't know exactly how to use an Array class. Is it same as we do in other programming languages. Can anyone explain me how an Array Class is Used in JavaScript? Please help me soon as possible.!!
    "Every man is guilty of all the good he did not do". - Voltaire

  2. #2
    Join Date
    Jul 2006
    Posts
    286

    Re: How an Array Class is Used in Javascript?

    If you have did the Java, then you can understand the process very easily, since there is not much difference in creating an arrays in JavaScript. For using an array in JavaScript follow the steps mentioned below :
    1. First you will have to create an object. You can create an object by using the following code :
      Code:
      var aValues = new Array();
    2. Before proceeding further, I would like to tell that you should know how many times an items of array will take place. Then you would have to pass the array size as a parameter. Use the following code for doing that :
      Code:
      var aValues = new Array(10);
    3. Then you will require to populate the array with bracket notation, which is very similar to process that you do in Java.

    Code:
    var aNumbers = new Array();
          aNumbers[0] = “one”;
          aNumbers[1] = “two”;
          aNumbers[2] = “three”;
    Hope that these steps helps you in using the array in JavaScript.
    IF you hate me, please don't mention it. I know who hates me and who doesn't. You really do not have to make fun of people....

  3. #3
    Join Date
    Aug 2006
    Posts
    227

    Re: How an Array Class is Used in Javascript?

    I don't know much about the Array class that is used in JavaScript, but I know about an array that are used in Java. It would be helpful about the information of array class used in Java, so I am giving more details about it. In Java, the ArrayList class extends AbstractList and implements the List interface. Also the arrays are of fixed length in Java which means you cannot grow or shrink the arrays later on. And suppose if you want to do the changes in array then you would have to use the ArrayList which is a collections framework. An ArrayList is a variable-length array of object references. The following are the constructors of an ArrayList :
    • ArrayList( )
    • ArrayList(Collection c)
    • ArrayList(int capacity)
    I do to dead flowers what people at morgues do to dead people. Suck all the moisture out, dip them in plastic, paint them up pretty and put them in a nice frame.

  4. #4
    Join Date
    Jul 2006
    Posts
    289

    Re: How an Array Class is Used in Javascript?

    In simple words you can say that an arrays are one way of keeping a program more organized. The arrays are similar for any programming languages. They only differ in the coding. Suppose you wanted to write out some quotes, and use variables for each one of the quotes. Then you can define that number of the variable. For example lets say that you want to define the 3 variable, then you can do in this way :
    quote1="I an new to JavaScript.";
    quote2="I know little bit of Java.";
    quote3="C++ is well known.";
    To define an array, we need to follow the following form :
    Code:
    var Name_of_Array= new Array(number_of_elements);
    So, for the above 3 quotes, you can write as :
    Code:
    var quote= new Array(3);
    Signatures reduce available bandwidth

  5. #5
    Join Date
    Nov 2008
    Posts
    1,192

    Re: How an Array Class is Used in Javascript?

    The arrays are used to store an information in any programming languages. You might have seen it in the tags that are accessed using the document object are often returned as an array. You can use an arrays as stacks, queues, etc. in the JavaScript. Also the main difference in the array used in C language and an array used in JavaScript are unlike C-like syntax, an array of characters in JavaScript is not the same as a string: the string class has other methods for string processing that have nothing to do with arrays, and the 2 are not interchangeable. ArrayList java.util.ArrayList allows for expandable arrays.

  6. #6
    Join Date
    Mar 2008
    Posts
    672

    Re: How an Array Class is Used in Javascript?

    I would like to tell you about the constructors that are used in JavaScript. The constructor property of JavaScript returns a reference to the array function that creates the object. You can just have a look on the following code in which I have used the array.constructor property which returns the function name. Hope that it would be better for you to understand once you have a look on the code :
    HTML Code:
    <html>
    <head>
    <h1>Constructor Property in JavaScript Array </h1>
    <script type="text/javascript">
    var array = new Array("Welcome", "Mumbai", "Hotels");
    document.write("<b>The function of this object's instance is: </b>" + array.constructor+"<br>"); 
    </script>
    <body bgcolor="lightOrange"/>
    </head>
    <b>[The array.constructor property returns the function that created the object's instance.]</b>
    </html>

Similar Threads

  1. Replies: 8
    Last Post: 08-10-2011, 11:06 PM
  2. javascript get element by class
    By GlassFish in forum Software Development
    Replies: 5
    Last Post: 06-03-2010, 09:05 PM
  3. JavaScript to convert an Array to String
    By KAMANA in forum Software Development
    Replies: 3
    Last Post: 09-12-2009, 05:30 AM
  4. Creating an array from a class
    By Kingfisher in forum Software Development
    Replies: 3
    Last Post: 25-11-2009, 02:50 PM
  5. To find key in array for Javascript.
    By Austinage in forum Software Development
    Replies: 3
    Last Post: 31-07-2009, 08:13 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,815,756.87626 seconds with 16 queries