[英]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 我从mongodb服务器获取信息,值之一是这样的字符串
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. 您可以使用javascript拆分功能,这将返回一部分数组。
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. 您可以使用split()方法解决此问题。
Example: 例:
var myString = 'Fire, Water, Ice, Steel';
var myArray = myString.split(', ');
console.log(myArray); // [ 'Fire', 'Water', 'Ice', 'Steel' ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.