Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #8613

Re: Create a multi-dimensional array

From Dr J R Stockton <reply1147@merlyn.demon.co.uk>
Newsgroups comp.lang.javascript
Subject Re: Create a multi-dimensional array
Date 2011-11-24 18:42 +0000
Organization Home
Message-ID <y6YD3kFVApzOFwPL@invalid.uk.co.demon.merlyn.invalid> (permalink)
References <1c993ed8-05a6-43b4-a28f-e9b0ad1c6241@c16g2000pre.googlegroups.com> <jaim56$151$1@dont-email.me>

Show all headers | View raw


In comp.lang.javascript message <jaim56$151$1@dont-email.me>, Wed, 23
Nov 2011 13:41:28, Jukka K. Korpela <jkorpela@cs.tut.fi> posted:

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

It will help if the reader is accustomed to languages which support
multi-dimensional arrays, and wants in JavaScript the effect of a two-
dimensional array.  Those languages include Algol (IIRC), Pascal/Delphi,
and English.

> The notation [3][5] is not meaningful as such.

The author meant to say that it is pseudocode.  It's certainly
meaningful in some dialects of pseudocode.


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

Provided that one recalls that a5 must be an array (maybe empty) before
the first of those assignments, and that a5[1] must be an array (maybe
empty) before the second of those assignments.

-- 
 (c) John Stockton, nr London UK  ?@merlyn.demon.co.uk  IE8 FF8 Op11 Sf5 Cr15
   news:comp.lang.javascript FAQ <http://www.jibbering.com/faq/index.html>.
   <http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
   <http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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