I have this code:
var users = [];
users.push({
username: "admin",
password: "admin"
});
this.showAllUsers = function() {
console.log(users);
};
this.addUser = function(user) {
if('username' in user && 'password' in user) {
users.push({
username: user.username,
password: user.password
})
}
else {
throw "Invalid object";
}
};
this.isExist = function(user) {
console.log(users.indexOf({
username: "admin",
password: "admin"
}));
};
Why console log prints all the time -1 ? Users array contains array with object with property username: "admin: and password: "admin".