I have an array of objects that I would like to break down into another set of arrays based on a property of the objects in the array.
For example, I have some object such as this:
function Object1(property1, property2, property3){
this.property1 = property1;
this.property2 = property2;
this.property3 = property3;
}
Then, I have an array with several of these objects, however some share the same value for property1, such as:
const obj1 = new Object1(id_1, some_value_1, some_value_2);
const obj2 = new Object1(id_2, some_value_2, some_value_2);
const obj3 = new Object1(id_1, some_value_3, some_value_3);
const obj4 = new Object1(id_2, some_value_4, some_value_4);
var objectArray = [obj1, obj2, obj3, obj4];
Now given this array, I want to create new arrays based on Object1.property1, so that I end up with the following arrays:
array1 = [obj1, obj3];
array2 = [obj2, obj4];
This is no doubt not much of a task but I can't think atm. Thanks for input.
There is a caveat or two: I won't always know how large the objectArray is, and I won't know how many objects within that array share a property, meaning need x number of new arrays.