I have this array:
var array = {
item: 'value',
subArray: []
}
I would like to use a $.each function to loop through some data and push key:value values into the subArray. After pushing the array should look like this:
var array = {
item: 'value',
subArray: [item: 'value', item: 'anothervalue', ...]
}
I'm currently using this inside my $.each loop:
$('class').each(function() {
array.subArray.push({ 'item': $(this).html() });
});
However, the current result is this:
var array = {
item: 'value',
subArray: [{item: 'value'}, {item: 'anothervalue'}, ...]
}
Any advice would be appreciated. Thanks!