Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
554 views
in Technique[技术] by (71.8m points)

javascript - 将JavaScript数组转换为逗号分隔列表的简便方法?(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.)((我知道如何迭代数组并通过连接自己构建字符串,如果这是唯一的方法。))   ask by Herb Caudill translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

 var arr = ["Zero", "One", "Two"]; document.write(arr.join(", ")); 


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.8k users

...