$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · easy · #244

Which fix removes the bug?

const prices: Record<string, number> = { tea: 2, jam: 5 };
for (const p of prices) {
  console.log(p); // expected 2, then 5
}
  1. Use for (const p in prices)
  2. Type it as number[] instead
  3. Add as const to the object
  4. Loop over Object.values(prices)
Plain objects are not iterable, so for...of throws. Object.values gives an array of the values; for...in would give the keys.
Play Problem Solving ▸