A question in javascript

  • Java
  • Thread starter AllenHe
  • Start date
  • #1
AllenHe
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
14,168
8,148
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.
 

Suggested for: A question in javascript

  • Last Post
Replies
2
Views
104
  • Last Post
Replies
9
Views
184
  • Last Post
Replies
11
Views
136
  • Last Post
Replies
1
Views
102
Replies
5
Views
762
Replies
1
Views
171
  • Last Post
Replies
6
Views
538
  • Last Post
6
Replies
187
Views
6K
  • Last Post
Replies
4
Views
431
  • Last Post
Replies
11
Views
710
Top