node.js get data from array or object -
I am trying to access data from a function, I thought it was an array, so I did not have the .parse ()
, to divide JSON Sir Auged objects into Word objects, but this is not a real array, so I do not know how it is.
This code is:
app post ('/', function (request, response) {console.log ('post oak' ); Mongoose.Connect ('Mongodb: // localhost'); var db = mongoose connection; db.on ('error', console.air bit (console, 'connection error:')); db once ( 'Open', function callback () {database.findByName (request.body.username.toLowerCase), function (error, data) {if (error) {response.render ('index', {'Title': title, Result ':' Error, please try again later. '});} If (data Gt> {console.log (JSON.stringify (data)); if (request.body.username == Data.username & request.body.password == data.password) {response.render ( 'Index', {'title': title, 'result': 'log in success.'})}} Other {response.render ('index', {'title': title, 'result': 'user name / Invalid password. '});}} Response.render (' index ', {' title ': title,' result ':' not found '});});}); });
A if
statement is not working because data.object ()
is undefined so I created the log of data and I Geton: [["username": "maggns", "password": "22542214", "other data"}]
JSON. Pars is not working, it throws me an error Any information on how to parse this data?
It seems that the data is an array so that you should use:
if (request.body.username == data [0] .username and request.body.password == data [0] .password) {// response}
< / Div>