Skip to content
Advertisement

how to check a condition in object array [closed]

I am trying to use an array map for checking if same username and password exist in an object array

database.map((obj)=>{
  if(values.name  === obj.name && values.password===obj.password){
    console.log("login success");
  } else {
    console.log("login Failed");
  }
});

Advertisement

Answer

You may use find for conditions:

const result = database.find((val)=> {
return val.name === obj.name && val.password === obj.password;
})

if(result){
console.log("login success");
}
else{
console.log("login failed");
}
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement