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

239
Visualizações
Is there a way to check to see if two objects have the same keys and the same values in JavaScript?

I am making a program in JavaScript that reads two words from the user and determines if the two are anagrams. My objects hold keys which are the letters of the word, and the values which is the amount of times it appears in the word. Here is how I am filling my objects at runtime:

for(var i = 0; i<word1.length; i++){
                      const curLetter = word1[i];
                      if(!dictWord1[curLetter]){
                          dictWord1[curLetter]=1;
                      }
                      else 
                      {
                          dictWord1[curLetter] += 1; 
                      }
                  } 
                  for(var i = 0; i<word2.length; i++){
                      const curLetter = word2[i];
                      if(!dictWord2[curLetter]){
                          dictWord2[curLetter]=1;
                      }
                      else
                      { 
                          dictWord2[curLetter] += 1;           
                      }
                  } 

Here is how they look when I console.log() them (I am using the words evil and live for this example)

Console.log results

I know how to loop through an object and print the keys and values, but is there a way in JavaScript I can compare the two? The way I am determining if they are anagrams is that I am seeing if the keys are the same and the values are the same in each object. Thanks in advance!

about 4 years ago · Juan Pablo Isaza
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