Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.roellig-ltd.de!open-news-network.org!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: Re: multi dim array Date: Wed, 18 Feb 2015 01:47:57 +0100 Organization: solani.org Lines: 52 Message-ID: References: <1bf955cc-1954-4144-a78c-930c8c3d5e5e@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1424220474 21928 eJwFwQcBwEAIBDBLrGPIAb74l9AE6uwb5nDD4U6Pcr+2lleIoLXRhyw2cFIdj05Nk0mF1P0boxCp (18 Feb 2015 00:47:54 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Wed, 18 Feb 2015 00:47:54 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 X-User-ID: eJwFwYEBwCAIA7CXoNLCzkHR/09YwiXXyRAVfHxSWrn3zER9d9Amj9VJw6k7iSL67HTWxuAHDS0QmA== In-Reply-To: <1bf955cc-1954-4144-a78c-930c8c3d5e5e@googlegroups.com> Cancel-Lock: sha1:B2UpfTP2P9FCsJFgAHoFBHkYN/Q= X-NNTP-Posting-Host: eJwFwQkBACAIA8BKPG5AHVD6R/AOTuXEIXiw2IyVRyTLRslp2WldN3+42pUI8Wtl+0DH/RLXELA= Xref: csiph.com comp.lang.javascript:26866 JRough wrote: > I'm trying to get this output from a ; > 1-1 > 1-3 > 1-5 > 3-3 > 3-5 > 5-5 > Would this be a 4 dimensional array? Why should that be a four dimensional array? If at all, it might be some representation of a two dimensional array. Note, however, that ECMAScript implementations (usually) have only one dimensional arrays. > Otherwise does this algorithm make sense? Which algorithm? > I had a test interview question and maybe I didn't understand the question. I was trying to do it anyway. This gets a syntax error. Well, you've screwed up. :) > var a = [1,3,5]; > for (var i=0;i< a.length; i++;){ > for( var j=9;j< a.length; j++){ You're trying to run a loop from 9 to 2 with a step (increment) of 1. Surely, that'll never execute the loop body. > var myarr=[]; > push.myarr[i,j] ; Most likely there is no `push` object, so you can't access one of its properties (`push.myarr`); probably you confused that with `myarr.push`. Anyhow, [i,j] is not a valid property accessor, but rather a syntax error. > console.log(myarr[i,j]); Same here. > }; > }; I suggest you learn about the syntax and semantics of ECMAScript, and make use of one of the many "interactive shells" widely available nowadays, such as the script consoles of contemporary browsers. -- Christoph M. Becker