How can I convert a comma-separated string to an array?

后端 未结 15 1620
温柔的废话
温柔的废话 2020-11-22 02:37

I have a comma-separated string that I want to convert into an array, so I can loop through it.

Is there anything built-in to do this?

For example, I have this

15条回答
  •  情歌与酒
    2020-11-22 02:59

    var array = string.split(',');
    

    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"].)

提交回复
热议问题