I want to print this out on the web.
[Mandatory] By creating an account, you agree to ArticleA, ArticleB, ArticleC, ... ArticleX.
Where Link is a component from material-ui
.
const createTACLine = (article, isMandatory) => {
let cline = '';
if (isMandatory) {
cline = cline + '[Mandatory] By creating an account, you agree to ';
}
Object.keys(article).forEach(function (key) {
cline = cline + <Link
component="button"
variant="body2"
to="/"
> +{article[key].name}+ </Link>;
if (parseInt(key) !== article.length - 1) {
cline = cline + ', ';
}
});
cline = cline + ".";
return cline;
};
where article here is
{
"id": 12,
"name": "ArticleA",
"url": "http://.....",
},
{
"id": 13,
"name": "ArticleB",
"url": "http://.....",
},
{
"id": 13,
"name": "ArticleC",
"url": "http://.....",
},
{
"id": 14,
"name": "ArticleX",
"url": "http://.....",
}
Instead, I get the following.
[Mandatory] By creating an account, you agree to [object Object], [object Object], [object Object], [object Object].
I see a lot of examples using push to push list items but I need to build a sentence here. Is there some other way to build a string using a loop and ?