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


Groups > comp.lang.javascript > #8572

Re: Create a multi-dimensional array

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> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
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

Followups directed to: comp.lang.javascript

Show key headers only | View raw


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] <http://PointedEars.de/es-matrix/#!>
-- 
Danny Goodman's books are out of date and teach practices that are
positively harmful for cross-browser scripting.
  -- Richard Cornford, cljs, <cife6q$253$1$8300dec7@news.demon.co.uk> (2004)

Back to comp.lang.javascript | Previous | NextPrevious 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