javascript - Node.js undefined properties -
i'm trying create log in window. code simple.
var employees = { '1' : { firstname: '', lastname: '', login: 'qwerty', password: '12345', }, '2' : { login: 'asdfg', password: '12345', }, }; app.post('/main', function(req, res) { if (!req.body) return res.sendstatus(400); console.log(req.body); for (var key in employees) { console.log(key['login']); console.log(key['password']); if ((key.login == req.body.login) && (key.password == req.body.password)) { res.render('main'); } else { app.get('/', function(req,res) { res.send(createindexpage()); }); }; }; });
why key.login , key.password return undefined? , why else block not run when if statement wrong?
look @ value of key
is:
var employees = { '1': { firstname: '', lastname: '', login: 'qwerty', password: '12345', }, '2': { login: 'asdfg', password: '12345', }, }; (var key in employees) { console.log(key); }
it property name (as string), not value of property.
console.log(employees[key]['login']);
give looking for.
Comments
Post a Comment