I am trying to create an array of object that will have multiple children. I have a table with data like this:
| PARENT | CHILD |
---------------------
| 123456 | 123 |
| 123456 | 124 |
| 123456 | 125 |
| 123457 | 345 |
| 123457 | 346 |
| 123457 | 347 |
....
I wish to get an array similar to this:
var arr_nos = { 123456 : [123, 124, 125], 123457 : [345, 346, 347]}
During a loop, I have this:
var arr_nos = [];
$('#table tbody tr').each(function( index ) {
var parent_no = elem.find('.parent_no').html();
var child_id = elem.find('.child_id ').html();
if(parent_no != '') {
child = [
child_id
]
arr_nos.push(parent_no, child);
}
});
But this results in:
["123456", Array(1), "123456", Array(1),"123456", Array(1), "123457", Array(1), "123457", Array(1), "123457", Array(1)]