如何使用 JavaScript 拆分逗号分隔的字符串?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5269856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 16:25:17 来源:igfitidea点击:
How to split comma separated string using JavaScript?
提问by user649802
I want to split a comma separated string with JavaScript. How?
我想用 JavaScript 分割一个逗号分隔的字符串。如何?
回答by thomas
var array = string.split(',')
and good morning, too, since I have to type 30 chars ...
早上好,因为我必须输入 30 个字符......
回答by Ralf de Kleine
var result;
result = "1,2,3".split(",");
console.log(result);
More info on W3Schoolsdescribing the String Split function.
关于W3Schools 的更多信息描述字符串拆分函数。
回答by CloudyMarble
Use
用
YourCommaSeparatedString.split(',');