954,152 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Using an array in Javascript

Hi. I need some help with arrays in JavaScript. I am creating a slideshow and have to store the images in an array on a separate file. I need some feedback as far as am I missing something in this file and how can I then call this array into my slideshow file? So far, I have:

<script type="text/javascript">

	// Create an array to hold image filenames
	var images = new Array();
 
	// Populate array with image filenames
	imgname[0] = 'home.jpg';
	imgname[1] = 'beach.jpg';
	imgname[2] = 'pool.jpg';
	imgname[3] = 'garden.jpg';
	imgname[4] = 'pond.jpg';
	imgname[5] = 'car.jpg';

</script>
Gia
Newbie Poster
8 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

You create a new array

var images = new Array();


and then you want to reference

imgname[0] = 'home.jpg';
...


..hmmm! names do not match.

Also, creating a new array, does not create a new array if images... you may want to create the elements of the array as:

images[0] = new image();
image[0].src = 'home.jpg';

...
HenryGR
Newbie Poster
24 posts since Mar 2008
Reputation Points: 10
Solved Threads: 4
 

Thanks! I'll try that.

Gia
Newbie Poster
8 posts since Nov 2007
Reputation Points: 10
Solved Threads: 0
 

> images[0] = new image();

images[0] = new Image();

~s.o.s~
Failure as a human
Administrator
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 733
 

Oops!
Sorry for the typo.
Thank YOU ~s.o.s~

HenryGR
Newbie Poster
24 posts since Mar 2008
Reputation Points: 10
Solved Threads: 4
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You