A couple of corrections to your original function ought to do it.
var output = {}; // empty object
$.each(fruits, function (index, fruit)
{
var key = fruit.id;
// check property exists otherwise initialize it
if (!output[key]) output[key] = [];
output[key].push(fruit);
});
1
solved How to generate asscoiate array of objects in javascript?