From a service call, I receive similar JSON data like follows:
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"}];
I need to split this into multiple arrays of objects dynamically, based on areaCode.
Or create a new object dynamically based on areaCode.
this.myArray= this.data.map(item => item.areaCode)
.filter((value, index, self) => self.indexOf(value) === index);
I have thoughts of using the map function and filtering it out based on the areaCode, and then perhaps creating a new object with arrays based on areaCode. I just cannot seem to wrap my head around the process. If anyone could offer some advice I would be grateful.