Properties as arrays

Discussion in 'Javascript' started by Helpful person, Nov 24, 2009.

  1. Please note that I am a beginner at javascript.

    I have written the following script that works fine.

    photos = new Array();
    photos.image = "image";
    // photos.title(0) = "title"
    document.write(photos.image);

    However, I wish to define the propery photos.title as an array. When
    I remove the comment // I get errors. How do I define
    photos.title as an array?

    Thanks in advance.
     
    Helpful person, Nov 24, 2009
    #1
    1. Advertising

  2. Helpful person <> writes:

    > Please note that I am a beginner at javascript.
    >
    > I have written the following script that works fine.
    >
    > photos = new Array();


    If photos is not an array, you can use
    var photos = new Object();
    or just
    var photos = {};

    > photos.image = "image";
    > // photos.title(0) = "title"


    If photos.title should be an array, you need to create the array:
    photos.title = [];
    and then assign to it:
    photos.title[0] = "title";

    > document.write(photos.image);
    >
    > However, I wish to define the propery photos.title as an array. When
    > I remove the comment // I get errors. How do I define
    > photos.title as an array?


    Either
    photos.title = [];
    or
    photos.title = new Array();

    /L
    --
    Lasse Reichstein Holst Nielsen
    'Javascript frameworks is a disruptive technology'
     
    Lasse Reichstein Nielsen, Nov 24, 2009
    #2
    1. Advertising

  3. On Nov 24, 3:55 pm, Lasse Reichstein Nielsen <>
    wrote:
    > Helpful person <> writes:
    > > Please note that I am a beginner at javascript.

    >
    > > I have written the following script that works fine.

    >
    > >  photos = new Array();

    >
    > If photos is not an array, you can use
    >    var photos = new Object();
    > or just
    >    var photos = {};
    >
    > >  photos.image     =  "image";
    > > // photos.title(0)     =  "title"

    >
    > If photos.title should be an array, you need to create the array:
    >    photos.title = [];
    > and then assign to it:
    >    photos.title[0] = "title";
    >
    > > document.write(photos.image);

    >
    > > However, I wish to define the propery photos.title as an array.  When
    > > I remove the comment   //   I get errors.  How do I define
    > > photos.title as an array?

    >
    > Either
    >   photos.title = [];
    > or
    >   photos.title = new Array();
    >
    > /L
    > --
    > Lasse Reichstein Holst Nielsen
    >  'Javascript frameworks is a disruptive technology'


    Thank you very much for answering my elementary questyion.

    www.richardfisher.com
     
    Helpful person, Nov 24, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    0
    Views:
    920
    Nathan Sokalski
    Oct 17, 2005
  2. =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?=

    CompositeControls: ViewState properties w/ Mapped properties probl

    =?Utf-8?B?Q2hyaXN0b3BoZSBQZWlsbGV0?=, Jan 19, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    1,142
    Steven Cheng[MSFT]
    Jan 19, 2006
  3. Kent Lichty
    Replies:
    0
    Views:
    838
    Kent Lichty
    Apr 16, 2004
  4. Victor Porton
    Replies:
    1
    Views:
    702
    Steven T. Hatton
    Aug 29, 2004
  5. Philipp
    Replies:
    21
    Views:
    1,134
    Philipp
    Jan 20, 2009
Loading...

Share This Page