将逗号分隔的字符串转换为数组 [英] Convert comma separated string to array
本文介绍了将逗号分隔的字符串转换为数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个逗号分隔的字符串,我想将其转换为数组,以便我可以遍历它。
I have a comma separated string that I want to convert into an array so I can loop through it.
有内置的内容吗?
例如我有这个字符串
var str = "January,February,March,April,May,June,July,August,September,October,November,December";
现在想用逗号拆分并存储在Array对象中
now want to split this by comma and store in Array object
推荐答案
var array = string.split(',');
MDN参考,主要有助于 limit
参数可能出现意外行为。 (提示:a,b,c.split(,,2)
出现在 [a,b]
,而不是 [a,b,c]
。)
MDN reference, mostly helpful for the possibly unexpected behavior of the limit
parameter. (Hint: "a,b,c".split(",", 2)
comes out to ["a", "b"]
, not ["a", "b,c"]
.)
这篇关于将逗号分隔的字符串转换为数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文