Andy
Andy

Reputation: 3170

Mapping a String to an Array

Given a string delimited by commas, how would I go about splitting it into an array in javascript?

Upvotes: 2

Views: 122

Answers (3)

Adam
Adam

Reputation: 44959

You use split. As in var myArray = "a,b,c".split(',');

Upvotes: 0

Donald Matheson
Donald Matheson

Reputation: 113

var array = string.split(",") should do it where string is your string variable

Upvotes: 5

Daniel Vassallo
Daniel Vassallo

Reputation: 344531

You can simply use the split() method on your string:

var myString = 'a,b,c';
var myArray = myString.split(',');

Upvotes: 3

Related Questions