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

239
Vistas
How can I get a key value from an array that has object inside

Imagine I have something like this:

const myArray = [
    {
        Email:example@example.com,
        Password:1234,
        Username:myname
    }
]

How can I access email value inside of object in easier way? I know can do some looping or mapping then using for of or something like that but is there any better way?

I want to do a check like that:

const otherArray = [
    {
        Email:example@notexample.com,
        Username:myname,
        Password:1234
    }
]

If the Email value inside of myArray is equals to the value of otherArray then if it does:

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

0

You can use Array.some() method.

Working Demo :

const myArray = [
    {
        Email: 'example@example.com',
        Username: 'myname',
        Password: 1234
    }, {
        Email: 'example1@example.com',
        Username: 'myname1',
        Password: 5678
    }, {
        Email: 'example2@example.com',
        Username: 'myname2',
        Password: 8756
    }
];

const otherArray = [
    {
        Email: 'example@notexample.com',
        Password: 1234,
        Username: 'myname'
    }
];

const res = myArray.some(obj => obj.Email === otherArray[0].Email);

console.log(res); // false as example@example.com is not equal to example@notexample.com.

about 4 years ago · Juan Pablo Isaza Denunciar

0

Some examples (with the syntax error fixed on the values)

let myname = "I create sntax errors";
const myArray = [{
  Email: "example@example.com",
  Password: "1234",
  Username: myname
}];

const otherArray = [{
  Email: "example@notexample.com",
  Username: myname,
  Password: "1234"
}];

const otherArrayAlso = [{
  Email: "example@example.com",
  Username: myname,
  Password: "1234"
}];
let isMatch = myArray[0].Email == otherArray[0].Email;
console.log(myArray[0].Email, otherArray[0].Email);
console.log("IsMatch:", isMatch);
console.log(myArray[0].Email == otherArrayAlso[0].Email);

about 4 years ago · Juan Pablo Isaza Denunciar

0

You can simply check like this

const myArray = [
  {
    Email: 'test@test.com',
    Age: 30,
  },
  {
    Email: 'One@test.com',
    Age: 24,
  },
  {
    Email: 'Two@test.com',
    Age: 20,
  },
]

const otherArray = [
  {
    Email: 'Three@test.com',
    Age: 30,
  },
  {
    Email: 'test@test.com',
    Age: 24,
  },
  {
    Email: 'Four@test.com',
    Age: 20,
  },
]

let found = false;

const otherArrayEmails = otherArray.map(item => item.Email);
for (let i = 0; i < myArray.length; i++) {
   if (otherArrayEmails.includes(myArray[i].Email)) {
      found = true;
      break;
   }
} 
console.log(found)

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