I have an array of products that have 5 properties, one of those being "category". What i want to achieve is to get a new array that separates these products by category BUT with the category in a "title" property, so the final array has the shape of
[{
title: "category1",
data: [{product1,product2,...}]
},{
title: "category2",
data: [{product3,product4,...}]}
]
I found a similar question but that doesnt give me the "title" prop, instead it gives me:
[{
cateogry1: [{product1,product2,...}],
category2: [{product3,product4,...}],
}]
And this doesnt work because im trying to use this array in a SectionList in ReactNative which needs the data to have the other specific shape. If anyones know a way in which I can separate the array like this or use the original array in a SectionList that would be great.
You can use the reduce() method of the Array to "map" your items one after the other