将JavaScript数组转换为逗号分隔列表的简便方法?

本文探讨了如何在JavaScript(或jQuery)中简便地将一维字符串数组转换为逗号分隔的列表。主要介绍了Array.prototype.join()方法和数组的toString()方法作为实现这一目标的有效方式。
摘要由CSDN通过智能技术生成

本文翻译自:Easy way to turn JavaScript array into comma-separated list?

I have a one-dimensional array of strings in JavaScript that I'd like to turn into a comma-separated list. 我在JavaScript中有一个一维的字符串数组,我想把它变成以逗号分隔的列表。 Is there a simple way in garden-variety JavaScript (or jQuery) to turn that into a comma-separated list? 在花园种类的JavaScript(或jQuery)中有一种简单的方法可以将其转换为以逗号分隔的列表吗? (I know how to iterate through the array and build the string myself by concatenation if that's the only way.) (我知道如何迭代数组并通过连接自己构建字符串,如果这是唯一的方法。)


#1楼

参考:https://stackoom.com/question/qTc/将JavaScript数组转换为逗号分隔列表的简便方法


#2楼

The Array.prototype.join() method: Array.prototype.join()方法:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值