[英]How to convert 2D array in to comma separated string in ReactJS
想在react.js
多維數組轉換為逗號分隔的字符串。 例如
suggestionChips: Array(6)
0: {identifier: "1", description: "One"}
1: {identifier: "2", description: "Two"} `
輸出應該在逗號分隔的字符串中: One , Two
這可能對你有幫助。
let suggestionChips = [{identifier: "1", description: "One"},{identifier: "2", description: "Two"}]; let output = suggestionChips.map(chip => chip.description).join(', ') console.log("Output", output);
您可以這樣做(使用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.