Posted By

jamesming on 07/21/08


Tagged

array


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

inkdeep


Multidimensional Array


 / Published in: JavaScript
 

URL: http://www.developerfusion.co.uk/show/2310/

  1. var sDataArray=MultiDimensionalArray(7,2);
  2.  
  3. sDataArray[6][1] = "This has been stored successfully!";
  4.  
  5. alert(sDataArray[6][1]);
  6.  
  7. function MultiDimensionalArray(iRows,iCols)
  8. {
  9. var a = new Array(iRows);
  10. for (var i=0; i < iRows; i++)
  11. {
  12. a[i] = new Array(iCols);
  13. for (var j=0; j < iCols; j++)
  14. {
  15. a[i][j] = "";
  16. }
  17. }
  18. return(a);
  19. }
  20.  
  21.  
  22.  
  23.  
  24. // THREE DIMENSIONS
  25.  
  26. function MultiDimensionalArray(iRows,iCols,iDepth)
  27. {
  28. var a = new Array(iRows);
  29. for (var i=0; i < iRows; i++)
  30. {
  31. a[i] = new Array(iCols);
  32. for (var j=0; j < iCols; j++)
  33. {
  34. a[i][j] = new Array(iDepth);
  35. for (var m=0; m < iDepth; m++)
  36. {
  37. a[i][j][m] = "";
  38. }
  39. }
  40. }
  41. return(a);
  42. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: jamesming on June 16, 2010

http://www.kavoir.com/2009/02/javascript-multi-dimensional-array.html

You need to login to post a comment.