I have,
{ mydata.map(({ name }) => ( <p style = {{ display: "inline" }} > { " " } { name }, </p>)) }
How can I remove the last comma in banana, apple, orange,
the result of the code, that is, the one after orange
and make it look something like this: banana, apple, orange
?
Thank you very much!
Advertisement
Answer
{mydata.map(({name}, idex) => ( <p style={{display:"inline"}}> {" "}{name} {index === mydata.length - 1 ? "" : ","} </p> ))}