Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove the last comma from a map?

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!

like image 623
Tom Avatar asked Oct 15 '25 16:10

Tom


1 Answers

{mydata.map(({name}, idex) => (
                            <p style={{display:"inline"}}>
                                {" "}{name} {index === mydata.length - 1 ? "" : ","}
                            </p>
                            ))}
like image 73
alisasani Avatar answered Oct 18 '25 06:10

alisasani



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!