简体   繁体   English

将 JavaScript 数组转换为逗号和引号分隔的字符串列表的简单方法?

[英]Easy way to turn JavaScript array into comma AND Quotation Marks separated string list?

I wanted to know if there was a function that could turn an array into a string separated with Quotation Marks and commas in JS?我想知道是否有一个 function 可以将数组转换为 JS 中用引号和逗号分隔的字符串?

var array = [1,2,3]

var result = '["1", "2", "3"]';

You can use .map to convert array elements to strings, and JSON.stringify to get the resulting string:您可以使用.map将数组元素转换为字符串,并使用JSON.stringify获取结果字符串:

 const array = [1,2,3]; const result = JSON.stringify(array.map(String)); console.log(result);

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

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