Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #8558
| From | "Jukka K. Korpela" <jkorpela@cs.tut.fi> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Create a multi-dimensional array |
| Date | 2011-11-23 13:41 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <jaim56$151$1@dont-email.me> (permalink) |
| References | <1c993ed8-05a6-43b4-a28f-e9b0ad1c6241@c16g2000pre.googlegroups.com> |
2011-11-23 13:04, Archos wrote: > To create a two dimensional array I use: > > var a4 = new Array(3); for (i=0; i<3; i++) a4[i]=new Array(5); > > In pseudoce: a4 = [3][5] The value of a4 is an array, where the elements are arrays. Calling it a two-dimensional array probably confuses rather than helps. The notation [3][5] is not meaningful as such. > Then, to create a 3 dim. array, I tried this one: > > var a5 = new Array(2); for (i=0; i<2; i++) a5[i]=new Array(2); for > (i=0; i<2; i++) a5[i]=new Array(2); I don't see what you regard as three-dimensional here, and I don't understand why you have the same 'for' loop twice. >>>> console.log(a5[1][0]) > undefined Naturally, because no value has been assigned to it. You have created an array with two elements, each of which is an array of two elements, each of which is initially undefined. Try setting e.g. a5[1] = ['Hello world', 42] or a5[1][0] = 'foobar' and you'll see that a5 works fine as a simulation of a two-dimensional array. -- Yucca, http://www.cs.tut.fi/~jkorpela/
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Create a multi-dimensional array Archos <raul.san@sent.com> - 2011-11-23 03:04 -0800
Re: Create a multi-dimensional array "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-11-23 13:41 +0200
Re: Create a multi-dimensional array John G Harris <john@nospam.demon.co.uk> - 2011-11-23 16:41 +0000
Re: Create a multi-dimensional array Dr J R Stockton <reply1147@merlyn.demon.co.uk> - 2011-11-24 18:42 +0000
Re: Create a multi-dimensional array "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2011-11-25 01:53 +0200
Re: Create a multi-dimensional array Gene Wirchenko <genew@ocis.net> - 2011-11-24 17:15 -0800
Re: Create a multi-dimensional array Erwin Moller <Since_humans_read_this_I_am_spammed_too_much@spamyourself.com> - 2011-11-23 12:46 +0100
Re: Create a multi-dimensional array Archos <raul.san@sent.com> - 2011-11-23 06:11 -0800
Re: Create a multi-dimensional array Denis McMahon <denismfmcmahon@gmail.com> - 2011-11-23 18:34 +0000
Re: Create a multi-dimensional array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-11-23 21:33 +0100
csiph-web