O
O
Ostap2020-04-30 09:27:58
JavaScript
Ostap, 2020-04-30 09:27:58

Finding strings in an array of Javascript objects?

I ask for help.
I have an array of objects:

users=[
    {
        user: 'demo',
        password:'demo'
    },
    {
        user: 'admin',
        password:'admin'
    },

];

And there are two lines
const user ='demo';
const password='demo';

It is necessary that if worked if user ='demo' and password='demo' are in the array. That is, as if the authorization of the user.
Thank you

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2020-04-30
@Your_Uncle_Ostap

if(users.some(u=>u.user == user && u.password == password)){
//Как бы авторизация
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question