Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

A question in javascript

  1. Sep 10, 2012 #1
    The general form for creating an array is:

    Myarray=new arrayname();

    But I don't understand wht should I type in the name of the array twice? Because I thought Myarray and arrayname is the same.
  2. jcsd
  3. Sep 10, 2012 #2


    Staff: Mentor

    DO you really mean something like this:

    MyArray myArray = new MyArray();

    where MyArray is a class and myArray is an instance?

    The statement above creates an instance called myArray of type MyArray. This is how you initialize myArray rather like assigning a value to it.

    MyArray myArray1;
    MyArray myArray2;
    MyArray myArray3;

    you can't use myArray1, myArray2, or myArray3 until you've assigned them a value that is until you do this:

    myArray1 = new MyArray();
    myArray2 = new MyArray();
    myArray3 = new MyArray();

    hope this helps.
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Similar Discussions: A question in javascript
  1. Javascript Help (Replies: 4)

  2. Frontpage JavaScript (Replies: 3)

  3. Javascript problem (Replies: 6)