将JavaScript数组转换成逗号分隔列表的简单方法?
16lz
2021-01-22
I have a one-dimensional array of strings in JavaScript that I'd like to turn into a comma-separated list. Is there a simple way in garden-variety JavaScript (or jQuery) to turn that into a comma-separated list? (I know how to iterate through the array and build the string myself by concatenation if that's the only way.)
我在JavaScript中有一个一维字符串数组,我想把它变成一个逗号分隔的列表。在普通的JavaScript(或jQuery)中,是否有一种简单的方法将其转换成逗号分隔的列表?(我知道如何遍历数组,如果这是唯一的方法,我可以通过连接自己构建字符串。)
14 个解决方案
#1
604
The Array.prototype.join() method:
Array.prototype.join()方法:
var arr = ["Zero", "One", "Two"];
document.write(arr.join(", "));
更多相关文章
- 创建一个未排序的数组,其中包含重复元素和唯一元素的总和
- js不使用jquery,调用ajax,传递数组,并接受,
- 使用jQuery.ajax post函数将javascript数组中的数据传递给服务器
- 如何将表列转换为数组?
- 如何修复JSON对象的假数组?
- 如何从SQL SELECT查询中的c#变量创建jQuery数组
- 导入地址簿联系人,存储在数组中并保存到数据库
- jquery解析php通过ajax传过来的json二维数组对象
- 从ajax查询返回的数组看起来还可以,但是它的器官没有正常显示