Closed wandanli closed 3 years ago
Loop an object In the return()
<div className="loop-container">
{
Object.entries(joblist).map(([key, value]) => (
<div id={key}>
Date: {key}
{
value.map(el => <div key={el.id}> {el.created_time} </div> )
}
</div>
))
}
</div>
use JSON.stringify
can let all type of value be the string
<Wrapper>
{Object.entries(growth).map(([key, value]) => {
const regex = /[\{\}\[\]\"\"]/g;
let growthValue = JSON.stringify(value)
.replace(regex, "")
.replace(/,/g, ", ");
return (
<StyledParagraph>
<StyledKey>{key.split("_").join(" ")}: </StyledKey>
<StyledValue>{growthValue}</StyledValue>
</StyledParagraph>
);
})}
three ways to get the value of an object: