Array Format

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Art X

    #1

    Array Format

    Does it matter how an Array is formatted ?

    For example, instead of this way:

    var my_photos = new Array("photo1.j pg", "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.

  • RobB

    #2
    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.j pg", "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 "

    ];

    Comment

    • Mick White

      #3
      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.j pg", "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+".jp g";
      }
      return temp;
      }
      my_photos=photo s(5);
      alert(my_photos .join("\n"))
      </script>
      Mick

      Comment

      • Art X

        #4
        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.

        Comment

        Working...