Array Format

A

Art X

Does it matter how an Array is formatted ?

For example, instead of this way:

var my_photos = new Array("photo1.jpg", "photo2.jpg", "photo3.jpg");

can I do it this way:

var my_photos = new Array(
"photo1.jpg",
"photo2.jpg",
"photo3.jpg"
);

Ease of editing is the reason why I'm asking this.

Later, Art.
 
R

RobB

Art said:
Does it matter how an Array is formatted ?

Nope (think you meant 'array declaration').
For example, instead of this way:

var my_photos = new Array("photo1.jpg", "photo2.jpg", "photo3.jpg");

can I do it this way:

var my_photos = new Array(
"photo1.jpg",
"photo2.jpg",
"photo3.jpg"
);
Yup.

Ease of editing is the reason why I'm asking this.

Later, Art.

Could also use a literal:

var my_photos =
[

"photo1.jpg" ,
"photo2.jpg" ,
"photo3.jpg"

];
 
M

Mick White

Art said:
Does it matter how an Array is formatted ?

For example, instead of this way:

var my_photos = new Array("photo1.jpg", "photo2.jpg", "photo3.jpg");

can I do it this way:

var my_photos = new Array(
"photo1.jpg",
"photo2.jpg",
"photo3.jpg"
);

<script type="text/javascript">
function photos(howmany){
var temp=[];
for(var h=1;h<howmany+1;h++){
temp[temp.length]="photo"+h+".jpg";
}
return temp;
}
my_photos=photos(5);
alert(my_photos.join("\n"))
</script>
Mick
 
A

Art X

Thanks Rob and Mick.

Rob:

"(think you meant 'array declaration')"

The sad truth is that I rarely know what I mean. I simply guessed wrong
again. lol

I forgot about the literal. Now that you've pointed it out to me I do
remember reading about it in Flanagan's book.

Mick:

I have a text file (for my personal use only) of examples given to me.
Hope it's okay that I added your code for reference.

As usual I greatly appreciate the help.

Later, Art.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,781
Messages
2,569,615
Members
45,301
Latest member
BuyPureganics

Latest Threads

Top