Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6532

How to separate an array by a property?

$
0
0

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.


Viewing all articles
Browse latest Browse all 6532

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>