After receiving JSON data from a service call, I am presented with the following structure:
myArray: any = [
{item: 'Jelly Beans', areaCode: 321, Company: "Bob's Candy"},
{item: 'Skittles', areaCode: 444, Company: "Jim's Candy"},
{item: 'Snickers', areaCode: 321, Company: "Bob's Candy"},
{item: 'M&Ms', areaCode: 444, Company: "Jim's Candy"},
{item: 'Gummy Bears', areaCode: 123, Company: "Sally's Candy"}];
My goal is to dynamically split this data into multiple arrays of objects based on their respective areaCodes.
Alternatively, creating a new object dynamically for each unique areaCode is another option.
this.myArray= this.data.map(item => item.areaCode)
.filter((value, index, self) => self.indexOf(value) === index);
I am considering using the map function to filter the data by areaCode and then possibly organizing it into new objects, but I'm struggling with visualizing the process. Any guidance or advice on how to approach this would be greatly appreciated.