Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!lightspeed.eweka.nl!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <3003096.SPkdTlGXAF@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Wed, 23 Nov 2011 21:33:26 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit Subject: Re: Create a multi-dimensional array Newsgroups: comp.lang.javascript References: <1c993ed8-05a6-43b4-a28f-e9b0ad1c6241@c16g2000pre.googlegroups.com> <4ecd3ca5$0$28487$a8266bb1@newsreader.readnews.com> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 37 NNTP-Posting-Date: 23 Nov 2011 21:33:26 CET NNTP-Posting-Host: f94e694a.newsspool1.arcor-online.net X-Trace: DXC=F2TaGePSX\WI?44J>Z[:RQic==]BZ:af^4Fo<]lROoRQ<`=YMgDjhgRgdMRoR:[^G_DZm8W4\YJN\;?f@h5gMfb\>@dMN77i@HQjafNhCg[9iU X-Complaints-To: usenet-abuse@arcor.de Xref: x330-a1.tempe.blueboxinc.net comp.lang.javascript:8572 Denis McMahon wrote: > var a5 = new Array(2); > for (var i=0; i<2; i++) > { > a5[i]=new Array(2); > for (var j=0; j<2; j++) a5[i][j]=new Array(2); > } Using arguments for the Array constructor is pointless here and error-prone. For that matter, using the Array constructor is unnecessary and potentially error-prone. Use the Array initializer instead; it is most certainly ubiquitous by now [1]: var a5 = []; for (var i = 0; i < 2; ++i) { a5[i] = []; for (var j = 0; j < 2; ++j) { a5[i][j] = []; } } Note that you can save memory if you do not create all potentially needed Array instances, but you have to pay for that with a bit of runtime (tests before access whether there already is an Array instance reference assigned). PointedEars ___________ [1] -- Danny Goodman's books are out of date and teach practices that are positively harmful for cross-browser scripting. -- Richard Cornford, cljs, (2004)