I am facing a challenge with an array provided below.
let arr = [{_firstName: "john", _lastName: "tom", _selectedDate: "03/12/2018", _slot: "6AM to 8AM", _phoneNumber: "+19173432970", _sport: "Soccer"},
{_firstName: "Jason", _lastName: "Deli", _selectedDate: "03/12/2018", _slot: "6AM to 8AM", _phoneNumber: "+19134592970", _sport: "Soccer"},
{_firstName: "Shey", _lastName: "Ford", _selectedDate: "03/12/2018", _slot: "6AM to 8AM", _phoneNumber: "+191767542970", _sport: "Soccer"},
{_firstName: "Jake", _lastName: "Hoss", _selectedDate: "03/13/2018", _slot: "6AM to 8AM", _phoneNumber: "+191723422970", _sport: "Soccer"},
{_firstName: "Vamsee", _lastName: "Karru", _selectedDate: "03/13/2018", _slot: "6AM to 8AM", _phoneNumber: "+18767692970", _sport: "Soccer"}];
I am looking for a solution where I can compare all objects in the array and extract similar ones into separate arrays dynamically.
For instance, considering the first 3 objects in the array above, if they have the same selectedDate, slot, and sport, I want them to be grouped together in a new dynamic array. The last 2 objects are different from the first 3 as they have different dates (selectedDate). Here is how I want the dynamic arrays to look like:
arr1 = [{_firstName: "john", _lastName: "tom", _selectedDate: "03/12/2018", _slot: "6AM to 8AM", _phoneNumber: "+19173432970", _sport: "Soccer"},
{_firstName: "Jason", _lastName: "Deli", _selectedDate: "03/12/2018", _slot: "6AM to 8AM", _phoneNumber: "+19145692970", _sport: "Soccer"},
{_firstName: "Shey", _lastName: "Ford", _selectedDate: "03/12/2018", _slot: "6AM to 8AM", _phoneNumber: "+19177612370", _sport: "Soccer"}];
arr2 = [{_firstName: "Jake", _lastName: "Hoss", _selectedDate: "03/13/2018", _slot: "6AM to 8AM", _phoneNumber: "+191776639270", _sport: "Soccer"},
{_firstName: "Vamsee", _lastName: "Karru", _selectedDate: "03/13/2018", _slot: "6AM to 8AM", _phoneNumber: "+19100692465", _sport: "Soccer"}];
I need assistance on achieving this through creating dynamic arrays. Can anyone provide guidance on how to accomplish this? Thank you.