Reputation: 89
Im taking info from a mongodb server and one of the values is a string like this
Fire, Water, Ice, Steel
Sadly its not an array and will be hard to separate. How can i do this?
Upvotes: 0
Views: 43
Reputation: 1024
Sadly its not an array and will be hard to separate. How can i do this?
You can make use of the split() method to solve this problem.
Example:
var myString = 'Fire, Water, Ice, Steel';
var myArray = myString.split(', ');
console.log(myArray); // [ 'Fire', 'Water', 'Ice', 'Steel' ]
Upvotes: 1
Reputation: 3844
You can use the javascript split function, this will return you an array of parts.
var str = "Fire, Water, Ice, Steel".split(", ");
console.log(str); // ["Fire", "Water", "Ice", "Steel"];
Upvotes: 3