簡體   English   中英

如何在 ReactJS 中將二維數組轉換為逗號分隔的字符串

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM