avatar
split strings into arrays in JavaScript using comma Javascript

• Using `split()` method

Input: 20,21,22
var arr = str.split(',');
Output: arr = ["20", "21", "22"]

• Using `split()` method with regular expression.

Input: 20,21,22
var arr = str.split(/[, ]+/);
Output: arr = ["20", "21", "22"]

• Using `split()` method and `map()` method.

Input: 20,21,22
var arr = str.split(",").map(function(item) {
  return parseInt(item, 10);
});
Output: arr = ["20", "21", "22"]
You need to login to do this manipulation!