PDA

View Full Version : How to access through index?



webdeveloper
02 Jul 2010, 04:17 AM
Hi,

I have the following code:



var test = {
arr : []
};

function addItem()
{
var p = {
a : 1,
b : 2
};

p.c = 3;

test.arr.push(p);
}

function readItem()
{
var tableObj = document.getElementById('tableId');
var row, cell;

for( var i = 0; i < test.arr.length; i++ )
{
row = tableObj.insertRow(tableObj.length);
for( var j = 0; j < )
{
cell = row.insertCell(j);
cell.innerHTML = test.arr[i].a; // I am having problem adding test.arr[].a/b/c
}
}
}


So at the line "cell.innerHTML = test.arr[i].a", I would actually like to index a/b/c into each cell created dynamically.

How can I achieve that?