Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Other Discussions
  3. Article Writing
  4. Multidimensional Array in JavaScript

Multidimensional Array in JavaScript

Scheduled Pinned Locked Moved Article Writing
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HubSnippets
    wrote on last edited by
    #1

    Several times, I have had to implement multidimensional array constructs using JavaScript but encountered difficulties. Since then, I'd been using other languages to achieve this purpose. But recently, I was able to devise a way around it which I would like to share: //Snippet var k = 0; var rows = new Array(4); var cols = new Array(4); var multiArray = new Array(rows, cols); for(var i=0; i<4; i++){ for(var j=0; j<4; j++){ multiArray[i][j] = ++k; } } for(var i=0; i<4; i++){ for(var j=0; j<4; j++){ document.writeln('
    '+multiArray[i][j]); } } I believe the code snippet is easy to comprehend and use. But it's interesting to know that JavaScript doesn't yet have an inherit way of programming multidimensional array. This implementation and any other that you might come across won't support many of the properties and methods like implementation in strong type languages (C++, C#, etc). Hopefully, there would be a library that will support all the features of multidimensional array implementation in JavaScript.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups