dynamic access array elements

wxdqz

New Member
Hi,
I was wondering how I could dynamically access an element in a javascript array, without having to make arrays within an array.

**I fill the customer array
var numr = 1;
cust[numr++] = new cust ("Joe","Doe","Doe Town");
cust[numr++] = new cust ("Lee","Main","Leeville");
numr --; // nr of rows
numrcols = cust.length; // nr of columns

**array definition
function cust(firstname,lastname,city)
{
this.firstname = firstname
this.lastname = lastname
this.city = city
}

** and now I want to put the array on screen (markup of the text is not important in this example)

** this works
for (var a=1; a <= numr ; a++)
{
document.write(customer[a].lastname + ", ");
document.write(customer[a].firstname + "<br>");
}

** but how must I write this one, without having to give the name of the element ?
for (var a=1; a <= numr ; a++)
{
for (var b=1; b <= numrcols ; b++)
{
document.write(customer[a].element +", ") // WRONG
}
}

Thanks,
Bart
 
Back
Top