How to i get the data from from [Object object]
?
如何从[Object]获取数据?
Here is an example of what i'm trying to do.
这是我要做的一个例子。
// Get data with dirty
var data = db.get('/htmltest')
// My test.db file
{"key":"foo","val":"barwhat?"}
{"key":"/htmltest","val":{"title":"Html Test","content":"<span>This is HTML</span>"}}
// the console.log gives me [Object Object]
// How do I get it to show the content of title (Html Test)
console.log(data);
3 个解决方案
#1
2
According to the documentation, the get
method returns the value for a given key. In that case you should be able to access the title
property like so:
根据文档,get方法返回给定键的值。在这种情况下,您应该能够访问title属性如下:
// Get data with dirty
var data = db.get('/htmltest')
// My test.db file
{"key":"foo","val":"barwhat?"}
{"key":"/htmltest","val":{"title":"Html Test","content":"<span>This is HTML</span>"}}
// the console.log gives me [Object Object]
// How do I get it to show the content of title (Html Test)
console.log(data.title);
#2
2
Another thing that you can do to help view your data for debugging is to use the util
inspect function.
另一种帮助查看数据进行调试的方法是使用util inspect函数。
var util = require('util');
var data = db.get('/htmltest');
console.log(util.inspect(data));
Again, this is only useful for debugging and inspecting the contents of objects.
同样,这只对调试和检查对象的内容有用。
#3
0
If you certify that your data
variable is a JSON object, you can also parse easily it and show all content in one row using JSON.stringify(data);
如果您证明您的数据变量是一个JSON对象,您也可以使用JSON.stringify(data)轻松解析它并在一行中显示所有内容;
#1
2
According to the documentation, the get
method returns the value for a given key. In that case you should be able to access the title
property like so:
根据文档,get方法返回给定键的值。在这种情况下,您应该能够访问title属性如下:
// Get data with dirty
var data = db.get('/htmltest')
// My test.db file
{"key":"foo","val":"barwhat?"}
{"key":"/htmltest","val":{"title":"Html Test","content":"<span>This is HTML</span>"}}
// the console.log gives me [Object Object]
// How do I get it to show the content of title (Html Test)
console.log(data.title);
#2
2
Another thing that you can do to help view your data for debugging is to use the util
inspect function.
另一种帮助查看数据进行调试的方法是使用util inspect函数。
var util = require('util');
var data = db.get('/htmltest');
console.log(util.inspect(data));
Again, this is only useful for debugging and inspecting the contents of objects.
同样,这只对调试和检查对象的内容有用。
#3
0
If you certify that your data
variable is a JSON object, you can also parse easily it and show all content in one row using JSON.stringify(data);
如果您证明您的数据变量是一个JSON对象,您也可以使用JSON.stringify(data)轻松解析它并在一行中显示所有内容;