Get your own website Result Size: 625 x 565
x
 
<!DOCTYPE html>
<html>
<body>
<h1>JavaScript Iterables</h1>
<h2>Make an Object Iterable</h2>
<p id="demo"></p>
<script>
// Create an Object
myNumbers = {};
// Make it Iterable
myNumbers[Symbol.iterator] = function() {
  let n = 0;
  done = false;
  return {
    next() {
      n += 10;
      if (n == 100) {done = true}
      return {value:n, done:done};
    }
  };
}
let text = ""
for (const num of myNumbers) {
  text += num +"<br>"
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>