From this array of objects, I’d like to get multiple arrays containing the objects that have the same values for the “id” property:
var obj1 = { id: 1, name: "apple"};
var obj2 = { id: 2, name: "pear"};
var obj3 = { id: 3, name: "melon"};
var obj4 = { id: 4, name: "cherry"};
var obj5 = { id: 2, name: "banana"};
var obj6 = { id: 1, name: "pinapple"};
var obj7 = { id: 1, name: "peach"};
var array = [obj1, obj2, obj3, obj4, obj5, obj6, obj7];
Example of the arrays I’d like to retrieve:
[{
id: 1,
name: "apple"
}, {
id: 1,
name: "pinapple"
}, {
id: 1,
name: "peach"
}]
[{
id: 2,
name: "pear"
}, {
id: 2,
name: "banana"
}]