Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to remove Comma from output element after mapping an Array in React js

I want the output like: Custom(F,T,S)

But output comes like,

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

My code:

‘Custom’ + (${data.state?.days?.map((item) => item.day ? item.day : '')})

Thanks………..

>Solution :

TL&DR :

'Custom' + (${data.state?.days?.filter((item) => !!item.day).map((item) => item.day)})

Array.map always transform all the entries of an array.
In your case, you have some some item that don’t have a "day".
So, you create a new array with empty elements

First, you have to filter your array :

data.state?.days?.filter((item) => !!item.day)

Then map through it

data.state?.days?.filter((item) => !!item.day).map((item) => item.day)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading