<!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>
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.