简体   繁体   English

如何在 ReactJS 中将二维数组转换为逗号分隔的字符串

[英]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 .想在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输出应该在逗号分隔的字符串中: 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 ;您可以这样做(使用array.map获取“描述” array.map )并将其作为字符串加入;

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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