TheKeith wrote:
Shouldn't this automatically create a multidimensional array? Can
someone help me? Thanks.
I use this helper function to create (and debug) multi-dimensional arrays.
//====== Multidimensional array
function MDArray (dimensions) {
// instantiate objects representing a multi dimensional array
// dimensions - array of numbers, ith number is nunmber of elements in
dimension i
this.length = dimensions[0]
this.dimensions = dimensions
if (dimensions.length>0) {
for (var i=0;i<this.length;i++) {
this[i] = new MDArray(dimensions.slice(1))
}
}
}
MDArray.prototype = new Array()
MDArray.prototype.constructor = MDArray
MDArray.prototype.toHTML = function(addr) {
var html = ''
if (this.dimensions.length > 2) {
for (var i=0;i<this.dimensions[0];i++) {
html += this[i].toHTML((addr?addr+',':'')+i)
}
}
else
if (this.dimensions.length == 2) {
html += '<BR>'+arguments[0]+'<TABLE BORDER=1>'
for (var i=0;i<this.dimensions[0];i++) { html += '<TR>'
for (var j=0;j<this.dimensions[1];j++) { html += '<TD>'
html += this[i][j] + '</TD>'
} html += '</TR>'
} html += '</TABLE>'
}
else {
html = this.toString()
} return html
}
mda = new MDArray([4,4,4,4])
mda[0][0][0][0] = 0
mda[1][1][1][1] = 1
mda[2][2][2][2] = 2
mda[3][3][3][3] = 4
document.write (mda.toHTML())
--
Richard A. DeVenezia
http://www.devenezia.com/downloads/sas/macros/?m=xmlib