A question in javascript

  • Java
  • Thread starter AllenHe
  • Start date
  • #1
74
0
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.
 

Answers and Replies

  • #2
12,392
6,153
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.
 

Related Threads on A question in javascript

Replies
9
Views
905
  • Last Post
Replies
1
Views
1K
Replies
3
Views
2K
Replies
11
Views
1K
  • Last Post
Replies
11
Views
3K
  • Last Post
Replies
4
Views
3K
  • Last Post
Replies
6
Views
2K
  • Last Post
Replies
3
Views
3K
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
2
Views
3K
Top