I am trying to use an array map for checking if same username and password exist in an object array
JavaScript
x
9
1
database.map((obj)=>{
2
if(values.name === obj.name && values.password===obj.password){
3
console.log("login success");
4
} else {
5
console.log("login Failed");
6
}
7
});
8
9
Advertisement
Answer
You may use find for conditions:
JavaScript
1
11
11
1
const result = database.find((val)=> {
2
return val.name === obj.name && val.password === obj.password;
3
})
4
5
if(result){
6
console.log("login success");
7
}
8
else{
9
console.log("login failed");
10
}
11