By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,288 Members | 3,027 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,288 IT Pros & Developers. It's quick & easy.

Array Issue

P: n/a
Hi there, the question:

I have this array:

var Thumbnails = new Array();
Thumbnails[0] = new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails[1] = new Array('2', 'sexy2.jpg', 'Sexy');
Thumbnails[2] = new Array('3', 'blue-sun-m.jpg', 'New Test');
Thumbnails[3] = new Array('4', 'viva_firefox_eats_ie.jpg', 'Firefox');

All fine at this point. But when a try to change the value for one:

Thumbnails[0][1] = '2';
Thumbnails[1][1] = '1';

This don't work. Any ideas ?, thanks in advanced.

-- eft0.

Jul 23 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
eft0 wrote:
Hi there, the question:

I have this array:

var Thumbnails = new Array();
Thumbnails[0] = new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails[1] = new Array('2', 'sexy2.jpg', 'Sexy');
Thumbnails[2] = new Array('3', 'blue-sun-m.jpg', 'New Test');
Thumbnails[3] = new Array('4', 'viva_firefox_eats_ie.jpg', 'Firefox');

All fine at this point. But when a try to change the value for one:

Thumbnails[0][1] = '2';
Thumbnails[1][1] = '1';

This don't work. Any ideas ?, thanks in advanced.


It should work. Unless you declared the variable "Thumbnails" within a
function, perhaps. How does it not *work*?
Mick

Jul 23 '05 #2

P: n/a

It meant:

Thumbnails[0][0] = '2';
Thumbnails[1][0] = '1';

eft0 wrote:
Hi there, the question:

I have this array:

var Thumbnails = new Array();
Thumbnails[0] = new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails[1] = new Array('2', 'sexy2.jpg', 'Sexy');
Thumbnails[2] = new Array('3', 'blue-sun-m.jpg', 'New Test');
Thumbnails[3] = new Array('4', 'viva_firefox_eats_ie.jpg', 'Firefox');

All fine at this point. But when a try to change the value for one:

Thumbnails[0][1] = '2';
Thumbnails[1][1] = '1';

This don't work. Any ideas ?, thanks in advanced.

-- eft0.

Jul 23 '05 #3

P: n/a
Lee
eft0 said:

Hi there, the question:

I have this array:

var Thumbnails = new Array();
Thumbnails[0] = new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails[1] = new Array('2', 'sexy2.jpg', 'Sexy');
Thumbnails[2] = new Array('3', 'blue-sun-m.jpg', 'New Test');
Thumbnails[3] = new Array('4', 'viva_firefox_eats_ie.jpg', 'Firefox');

All fine at this point. But when a try to change the value for one:

Thumbnails[0][1] = '2';
Thumbnails[1][1] = '1';

This don't work. Any ideas ?, thanks in advanced.


What does "this don't work" mean?
Are you sure you don't really want to change Thumbnails[0][0] and [1][0]?
Those are the elements that are initially numeric values.

Jul 23 '05 #4

P: n/a
Lee
eft0 said:


It meant:

Thumbnails[0][0] = '2';
Thumbnails[1][0] = '1';


Are you saying that you found your mistake, and now it works,
or that this is what you were really doing, and it still doesn't
work?

If the latter, then please don't retype code that "doesn't work".
Copy and paste the exact code, or we'll never find your typo.

Jul 23 '05 #5

P: n/a
On Fri, 04 Feb 2005 18:20:03 -0300 eft0 wrote:
Hi there, the question: I have this array: var Thumbnails = new Array();
Thumbnails[0] = new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails[1] = new Array('2', 'sexy2.jpg', 'Sexy');
Thumbnails[2] = new Array('3', 'blue-sun-m.jpg', 'New Test');
Thumbnails[3] = new Array('4', 'viva_firefox_eats_ie.jpg', 'Firefox'); All fine at this point. But when a try to change the value for one: Thumbnails[0][1] = '2';
Thumbnails[1][1] = '1'; This don't work. Any ideas ?, thanks in advanced. -- eft0.


Me thinks you're trying to do some things you should not be doing.
As I understand it, the way you show, just ain't kosher.
Thumbnails[0]="images/name1.jpg"
This is a ONE dimensional array to begin with.
You can have var Thumbnails="new Array("name1.jpg", "name2.jpg",
"name3.jpg")
But not Thumbnails[0]= new Array( what, ever)

Now you want to compound the issue by using a 2 dimensional array to do
what?
Thumbnails[0][0]="name1.jpg"
What you may want to try is something like this:

Thumbnails1=new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails2=new Array('2', 'sexy2.jpg', 'Sexy');

ThumbChoice=new Array()
ThumbChoice[0][0]=thumbnails1
ThumbChoice[0][1]=thumbnails2
Jul 23 '05 #6

P: n/a
Richard wrote:
On Fri, 04 Feb 2005 18:20:03 -0300 eft0 wrote:

Hi there, the question:
I have this array:


var Thumbnails = new Array();
Thumbnails[0] = new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails[1] = new Array('2', 'sexy2.jpg', 'Sexy');
Thumbnails[2] = new Array('3', 'blue-sun-m.jpg', 'New Test');
Thumbnails[3] = new Array('4', 'viva_firefox_eats_ie.jpg', 'Firefox');


All fine at this point. But when a try to change the value for one:


Thumbnails[0][1] = '2';
Thumbnails[1][1] = '1';


This don't work. Any ideas ?, thanks in advanced.


-- eft0.



Me thinks you're trying to do some things you should not be doing.


Coming from you, thats funny.
As I understand it, the way you show, just ain't kosher.
Thumbnails[0]="images/name1.jpg"
This is a ONE dimensional array to begin with.
There are no other kinds of Arrays in ECMAScript.
You can have var Thumbnails="new Array("name1.jpg", "name2.jpg",
"name3.jpg")
But not Thumbnails[0]= new Array( what, ever)
Ummm, YES you can. If you would bother learning the subject before
offering advice on the subject you might understand that.
Now you want to compound the issue by using a 2 dimensional array to do
what?
Thumbnails[0][0]="name1.jpg"
Thats not a "2 dimensional array", it is a nested array. Learn the
difference.

What you may want to try is something like this:

Thumbnails1=new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails2=new Array('2', 'sexy2.jpg', 'Sexy');

ThumbChoice=new Array()
ThumbChoice[0][0]=thumbnails1
ThumbChoice[0][1]=thumbnails2


Not withstanding your typos which would throw a "thumbnails1 is not
defined" error message, all you have done is create a nested array with
extra overhead.

Before you continue to give advice in this group, please at least read
the group, buy some books, do a lot of reading and get a basic grasp of
the language before you attempt to give answers.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Jul 23 '05 #7

P: n/a
Lee
Richard said:

On Fri, 04 Feb 2005 18:20:03 -0300 eft0 wrote:
Hi there, the question:

I have this array:

var Thumbnails = new Array();
Thumbnails[0] = new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails[1] = new Array('2', 'sexy2.jpg', 'Sexy');
Thumbnails[2] = new Array('3', 'blue-sun-m.jpg', 'New Test');
Thumbnails[3] = new Array('4', 'viva_firefox_eats_ie.jpg', 'Firefox');

All fine at this point. But when a try to change the value for one:

Thumbnails[0][1] = '2';
Thumbnails[1][1] = '1';

This don't work. Any ideas ?, thanks in advanced.

-- eft0.


Me thinks you're trying to do some things you should not be doing.
As I understand it, the way you show, just ain't kosher.
Thumbnails[0]="images/name1.jpg"
This is a ONE dimensional array to begin with.
You can have var Thumbnails="new Array("name1.jpg", "name2.jpg",
"name3.jpg")
But not Thumbnails[0]= new Array( what, ever)

Now you want to compound the issue by using a 2 dimensional array to do
what?
Thumbnails[0][0]="name1.jpg"
What you may want to try is something like this:

Thumbnails1=new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails2=new Array('2', 'sexy2.jpg', 'Sexy');

ThumbChoice=new Array()
ThumbChoice[0][0]=thumbnails1
ThumbChoice[0][1]=thumbnails2


The OP's code as posted is perfectly valid.
Yours is not.

You refer to ThumbChoice[0] as if it were an Array without
assigning an array reference to it.

Try this stragegy:
Read the post.
Test the code in the post.
If necessary, correct the code.
Test the code again.
Post comments about the code, possibly including new, tested code.

Jul 23 '05 #8

P: n/a
> I have this array:

var Thumbnails = new Array();
Thumbnails[0] = new Array('1', 'listing_34.jpg', 'Home View');
Thumbnails[1] = new Array('2', 'sexy2.jpg', 'Sexy');
Thumbnails[2] = new Array('3', 'blue-sun-m.jpg', 'New Test');
Thumbnails[3] = new Array('4', 'viva_firefox_eats_ie.jpg', 'Firefox');

All fine at this point. But when a try to change the value for one:

Thumbnails[0][1] = '2';
Thumbnails[1][1] = '1';

This don't work. Any ideas ?, thanks in advanced.


"This don't work" is not a useful description of a problem. I do have
some ideas though.

An array of arrays is not the best data structure for this application.
An array of objects is better.

var Thumbnails = [
{number: '1', url: 'listing_34.jpg', title: 'Home View'},
{number: '2', url: 'sexy2.jpg', title: 'Sexy'},
{number: '3', url: 'blue-sun-m.jpg', title: 'New Test'},
{number: '4', url: 'viva_firefox_eats_ie.jpg',
title: 'Firefox'}];

Now it is much clearer what you will be accessing and modifying as you
reach into the structures.

Thumbnails[0].number = '2';
Thumbnails[1].number = '1';

If you use an array inappropriately, you could easily be clobbering the
url when you are intending to change the number.

http://www.crockford.com/javascript/survey.html
Jul 23 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.