简体   繁体   English

我如何从mongoDB中分离一个字符串

[英]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.

相关问题 如何从 JavaScript 中的数组集合中分离数字和字符串? - How can i separate number and string from an Array collection in JavaScript? 如何将日期与字符串分开 - How do I separate the date from the string 如何使用JavaScript将每个字符从字符串写入单独的div? - How can I write each character from string to separate div using JavaScript? 如何将字符串 output 从模块写入单独的 node.js 文件中的文件 - How can I write the string output from a module to a file in a separate node.js file 如何在用户输入的字符串中分离函数并绘制该函数? - How can I separate a function in a string inputted by the user and plot this function? 如何将字符串拆分为单独的键和值? - How can I split a string into separate keys and values? 如何从 MongoDB 数组中仅返回 object 的字符串值 - How can I return only the string value of an object from a MongoDB array 如何从 mongodb 读取值? - how can I read values from a mongodb? 如何通过从单独的数组中匹配的字符串对象值从 3 个嵌套的 json 数组中提取对象值,然后在 html/javascript 中显示它 - How can I extract object values from 3 nested json arrays by matched string object values from a separate array and then display it in html/javascript 如何将键值对与Json字符串分开 - How do I separate key value pair from Json String
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM