Here is some code that I am working with:
let 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"
}));
};
I am puzzled as to why the console log always prints -1. The users array does indeed contain an object with properties username: "admin" and password: "admin".