Home > Blockchain >  React Map and Join from Object
React Map and Join from Object

Time:10-23

I tried to map and join from the object below.

production_countries: 

0: 
iso_3166_1: "GB"
name: "United Kingdom"

1: 
iso_3166_1: "US"
name: "United States of America"

I tried production_countries?.map((name) => (name.join(','))) and it doesn't render.

I want the result to be United Kingdom, United States of America

CodePudding user response:

I didn't try it but I think this will work.

production_countries?.map((item) => item.name).join(', ');

Because map will return array of only names then we join all elements of that array.

  • Related