简体   繁体   中英

How can i separate a string from mongoDB

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?

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"];

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' ]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM