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

109
Views
JavaScript for loop vs for(...in) loop

I just started studying the JS(3 weeks). I studied for loop and for ...in loop a few days ago and I checked the pros and cons of each of them. However, I tried to change for(...in) loop to for loop but there is an error. Could you check which part do I miss and wrong?

Here is a whole code

const getExamResult = (scores, requiredClasses) => {
  let newObj = {};
  let scoresKeys = Object.keys(scores);
  const scoresValue = Object.values(scores);
  // 학점 정보가 담겨 있는 객체
  const changeValue = {
    'A+': 4.5,
    'A': 4,
    'B+': 3.5,
    'B': 3,
    'C+': 2.5,
    'C': 2,
    'D+': 1.5,
    'D' : 1,
    'F' : 0
  };
  
  for (let i in scoresValue) {
    const key = scoresKeys[i];
    const value = scoresValue[i];
    const newValue = changeValue[value];
    
    newObj[key] = newValue;
  }

  for (let i = 0; i <scores.length; i++) {
    const key = scoresKeys[i];
    const value = scoresValue[i];
    const newValue = changeValue[value];

    newObj[key] = newValue;
  }
 for (let index in requiredClasses) {
    let element = requiredClasses[index];
    
    if (!newObj[element]) {
      newObj[element] = 0;
    }
  }
  
  return newObj;

}

I treid chagne this code

 for (let i in scoresValue) {
    const key = scoresKeys[i];
    const value = scoresValue[i];
    const newValue = changeValue[value];
    
    newObj[key] = newValue;
  }

to

  for (let i=0; i <Object.values(scores); i++){
    let key = scoresKeys[i];
    let value = scoresValue[i];
    const newValue = changeValue[value];

    newObj[key] = newValue;
  }

Thank you for your help 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!