I am currently receiving object segregatedData
as props. This object contains several properties but the one we will focus on is segregatedData.type1
Basically this is just an array of strings like this ['water','fire','water',earth']
What I'd like to is to be able to print out each string and then beside it is how many instances this value has been repeated. So in the example case the expected output would be water-2, fire-1, earth-1
Of course we'd have to delete the duplicates.
Here's what I have so far:
import React from "react";
import { Typography } from "@material-ui/core";
function TypesText(props) {
const { segregatedData } = props;
return (
<>
<Typography>Type1:</Typography>
{segregatedData.length && segregatedData.map((data) => data.type1 + " ")}
</>
);
}
export default TypesText;
Fairly basic, it just prints every type1
property with a blank string as its seperator. Anything that can point me in the right direction is appreciated.