Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!eternal-september.org!feeder.eternal-september.org!.POSTED!not-for-mail From: Dr J R Stockton Newsgroups: comp.lang.javascript Subject: Re: Create a multi-dimensional array Date: Thu, 24 Nov 2011 18:42:29 +0000 Organization: Home Lines: 43 Message-ID: References: <1c993ed8-05a6-43b4-a28f-e9b0ad1c6241@c16g2000pre.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain;charset=us-ascii Injection-Info: mx04.eternal-september.org; posting-host="UwYDIHu13GPq28RciNoAJA"; logging-data="26106"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19neB3KHGHkJhz3vPx/LF2HAhlzsDaJwq4=" User-Agent: Turnpike/6.05-S () Cancel-Lock: sha1:neS4eOEua2PNj3BaxpY5QqkF6t8= Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:8613 In comp.lang.javascript message , Wed, 23 Nov 2011 13:41:28, Jukka K. Korpela 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 . jscr maths, dates, sources. TP/BP/Delphi/jscr/&c, FAQ items, links.