Reputation: 15044
var data = {
row: row,
row2: row2
};
var tableData = [data.row,data.row2];
row objects contains lot of children objects too... now how would i placed my tableData to access each single objects. so it goes like this...
var tableData = [data.row[1],data.row[2],data.row[3],,data.row2];
Updated Question
var data = [row, row2];
In this case how would i access my row children objects.
Upvotes: 2
Views: 263
Reputation: 169531
var data = {key: value, ... };
var tableData = [];
for (var k in data) {
for (var i = 0, len = data[k].length; i < len; i++)) {
tableData.push(data[k][i]);
}
}
Use nested for loops and array.prototype.push
Edit
for (var j = 0, len = data.length;j < len;j++) {
for (var i = 0, len = data[j].length; i < len; i++)) {
tableData.push(data[j][i]);
}
}
You can replace for (var j in data)
with for (var j = 0, len = data.length; j < len; j++)
The latter
Upvotes: 1
Reputation: 46567
How about something like this...
var data = {
letters : ["a", "b", "c"],
numbers : ["0", "1", "2", "3"]
};
data.letters; // ["a", "b", "c"]
data.letters[0]; // "a"
data.numbers; // "0", "1", "2", "3"]
data.numbers[2]; // "2"
... or you could try this...
var data = {
letters : new Array("a", "b", "c"),
numbers : new Array("0", "1", "2", "3")
};
data.letters; // ["a", "b", "c"]
data.letters[0]; // "a"
data.letters.push("d"); // the array is now ["a", "b", "c"]
data.numbers; // ["0", "1", "2", "3"]
data.numbers[2]; // "2"
data.numbers.pop(); // the array is now ["0", "1", "2"]
For more info on JavaScript arrays, check out these links:
I hope this helps.
Hristo
Upvotes: 1
Reputation: 58619
Assign data.row first, then push data.row2, like this:
var tableData = data.row
tableData.push(data.row2)
Upvotes: 1