Suppose I have a set of objects that each contain data I want to store into a data table. Per the documentation, I would normally do something like:
var dataSet = [
['Trident', 'Internet Explorer 4.0', 'Win 95+', '4', 'X'],
['Trident', 'Internet Explorer 5.0', 'Win 95+', '5', 'C'],
['Trident', 'Internet Explorer 5.5', 'Win 95+', '5.5', 'A'],
['Gecko', 'Camino 1.0', 'OSX.2+', '1.8', 'A'],
['Gecko', 'Camino 1.5', 'OSX.3+', '1.8', 'A'],
['Gecko', 'Netscape 7.2', 'Win 95+ / Mac OS 8.6-9.2', '1.7', 'A'],
['Gecko', 'Netscape Browser 8', 'Win 98SE+', '1.7', 'A'],
['Gecko', 'Netscape Navigator 9', 'Win 98+ / OSX.2+', '1.8', 'A'],
['Misc', 'PSP browser', 'PSP', '-', 'C'],
['Other browsers', 'All others', '-', '-', 'U']
];
But my data is presented as an array of objects. Can I iterate through them in a for loop and get each piece of data? For example, if I have an object, obj, that contains a title and a some data, the following does not work:
var finalObj = "["
for (var i = 0; i < obj.length; i++) {
finalObj = finalObj + "['" + obj[i].title + "','" + obj[i].data + "']";
}
finalobj = finalObj + "]";
This results in my datatable only containing one letter per column. What is the proper way to create a string (or other object) that will be formatted like the example above?