JS Built-ins
ControlFlowintermediate

Control Flow β€” for...of: iterate over values

for...of iterates values of any iterable

Works with arrays, strings, Map, Set, and any iterable. Gives you the value directly, not the index.

Challenge: Write sumArray(arr) that uses for...of to sum all numbers in arr.

πŸ’‘ Hints (1)
  • β€’ for (const item of arr) gives you each element directly