如何将逗号分隔的字符串转换为数组?我有一个逗号分隔的字符串,我想要转换成一个数组,所以我可以循环通过它。有什么内置的吗?例如,我有这条绳子var str = "January,February,March,April,May,June,July,August,September,October,November,December";现在,我想用逗号将其拆分,然后将其存储在Array对象中。
3 回答
呼唤远方
TA贡献1856条经验 获得超11个赞
var str = "1,2,3,4,5,6";var temp = new Array();// this will return an array with strings "1", "2", etc.temp = str.split(",");
for (a in temp ) { temp[a] = parseInt(temp[a], 10); // Explicitly include base as per Álvaro's comment}
添加回答
举报
0/150
提交
取消