Connecting Tech Pros Worldwide Help | Site Map

Array Format

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 07:52 PM
Art X
Guest
 
Posts: n/a
Default Array Format

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.


  #2  
Old July 23rd, 2005, 07:52 PM
RobB
Guest
 
Posts: n/a
Default Re: Array Format

Art X wrote:[color=blue]
> Does it matter how an Array is formatted ?[/color]

Nope (think you meant 'array declaration').
[color=blue]
> 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"
> );[/color]

Yup.
[color=blue]
> Ease of editing is the reason why I'm asking this.
>
> Later, Art.[/color]

Could also use a literal:

var my_photos =
[

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

];

  #3  
Old July 23rd, 2005, 07:52 PM
Mick White
Guest
 
Posts: n/a
Default Re: Array Format

Art X wrote:[color=blue]
> 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"
> );[/color]

<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
  #4  
Old July 23rd, 2005, 07:52 PM
Art X
Guest
 
Posts: n/a
Default Re: Array Format

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.

 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.