Properties as arrays

H

Helpful person

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.
 
L

Lasse Reichstein Nielsen

Helpful person said:
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
 
H

Helpful person

Helpful person said:
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

Thank you very much for answering my elementary questyion.

www.richardfisher.com
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,053
Latest member
BrodieSola

Latest Threads

Top