How to i get the data from from [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);
How to i get the data from from [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);
Share
Improve this question
edited Feb 10, 2013 at 2:04
ThinkingStiff
65.4k30 gold badges147 silver badges241 bronze badges
asked Oct 10, 2012 at 14:08
dasmikkodasmikko
7062 gold badges8 silver badges30 bronze badges
3 Answers
Reset to default 3Another thing that you can do to help view your data for debugging is to use the util
inspect function.
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.
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 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);
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);