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

232
Vistas
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 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