Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

201
Vistas
How can i verify that a element is in my array?

I'm making a simple login system for a school project and I need to verify if the usernames and passwords are in my list, but i can't seem to figure it out

var logs = [
    {
        username: "admin",
        senha: "admin"
    },

    {
        username: "client",
        senha: "client"
    }
]


function login_func() {
    let user =  document.getElementById('email_val')
    let passwd =  document.getElementById('passwd')

    if(logs.includes(user.value)){
        alert('amogus')
    }
    
}

If anyone could help I'd be really thankfull

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

the best practice for this one will be the some prototype of an array:


    function isVerify(username, password){
    
        return logs.some(log => log.password === password && log.username === username)

    }

Of course, in the real world, you will encrypt passwords, and store them in DBs.

In case you want to return the logged-in user, use find instead:


    function login(username, password){
    
        return logs.find(log => log.password === password && log.username === username)

    }

This will return null in case of unmatch result.

about 4 years ago · Juan Pablo Isaza Denunciar

0

If you want the equivalent of includes but you need to check for a property of each object, use Array.some which takes a test function.

if (logs.some(obj => obj.username === user.value && obj.senha === passwd.value)) {

Of course, keep in mind that this type of 'authentication' will only serve for demonstration purposes and will never actually be useful for a real login.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can use find() method to find your user exists with your inputs.

const haveUser = (username, password) => !!logs.find(log => log.username == username && log.senha === password)

Important : When we wanna create an authentication system, should not create it on the Frontend side. It's completely wrong and risky because other developers open Dev Tools and can find your credentials.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda