Multidimensional Array


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.