简体   繁体   中英

How to convert 2D array in to comma separated string in ReactJS

Wanted to convert multi-dimensional array to comma separated string in react.js . Eg

   suggestionChips: Array(6)
   0: {identifier: "1", description: "One"}
   1: {identifier: "2", description: "Two"} `

Output should be in on comma separated string: One , Two

This may help you.

 let suggestionChips = [{identifier: "1", description: "One"},{identifier: "2", description: "Two"}]; let output = suggestionChips.map(chip => chip.description).join(', ') console.log("Output", output);

You can do this (get an array of 'description' with array.map ) and join it as a string ;

var suggestionChips = [{identifier: "1", description: "One"}, {identifier: "2", description: "Two"}]
console.log(suggestionChips.map(e => e.description).join(', '))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM