<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>