Do you have to assign new names in JS arrays?

They have: 2 posts

Joined: Nov 1999

Hey y'all. . . I was just wondering if you had to assign new names for each array you write -- that is, if you have multiple arrays in one script.

For example:

var MyArray = new Array(2)
MyArrayObjects[0] = "whatever.";
MyArrayObjects[1] = "whatever again.";

Now if you wanted another array -- for the array, and for the objects in that array, do you have to assign new names for them? Like this:

var MyArray2 = new Array(2)
MyArrayObjects2[0] = "blah";
MyArrayObjects2[1] = "blah again";

Also, do you have to make the name of the objects in the array the same as the name of the array itself?

Thanks, I just wanted to know -- I'm bulding a JS "proglet" (little program).

John Pollock's picture

He has: 628 posts

Joined: Mar 1999

As far as I know, you would need to give each array a new name. Otherwise, it would either overwrite the values or give an error.

The objects do have to have the same name as the array as well.

They have: 2 posts

Joined: Nov 1999

Thanks, John. . . Also, can you put HTML tags in between the quotation marks in the arrays? You know what I mean:

Array = new Array (2)
Array[0] = "<b>This text is in bold.</b>"
Array[1] = "<i>This text is in italics.</i>"

Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.