So I created the following:
I made this matrix array, each nested array has objects:
[
[
{ category: 'tech', product: "iPhone X", price: 320 },
{ category: 'food', product: "Cheerios", price: 5 },
],
[
{ category: 'food', product: "Snickers", price: 1.5 },
{ category: 'tech', product: "Air Pods", price: 129 },
],
]
Then, I created this function that loops through the array matrix:
function sortProducts (matrix) {
for (x=0;x<matrix.length;x++) {
for (y=0;y<matrix[x].length;y++){
console.log(matrix[x][y]);
}
}
}
Now, Im just trying to figure out how to create and return a new object containing the products sorted by their category like this:
{
tech: [ { tech product }, { tech product } ],
food: [ { food product }, { food product } ],
}