<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>JS Prototype and Iterables</title>
</head>
<body>
 
 <script>
      
const myIterable = {
   data: [1, 2, 3, 4, 5],
  [Symbol.iterator]: function () {
    let index = 0;

    return {
      next: () => {
        return index < this.data.length
          ? { value: this.data[index++], done: false }
          : { done: true };
      },
    };
  },
};

for (const value of myIterable) {
  document.write(value, `<br>`);
}
   
 </script>
  
  
</body>
</html>
Run Pen

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.