Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

246
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda