Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

237
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!