xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to iterate an iterator using while loop in JavaScript
JavaScript Online Editor
Run Code
More JavaScript Sample Codes
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Iterate an iterator using while loop in JavaScript</title> <!--Script tag is added to write JavaScript code inside it--> <script> let stringArray = ["Apple", "Banana", "Orange"]; let iteratorVar = stringArray.values(); //values() methods convert an array to an iterator var stringData = ""; // Iterate through the iterator let result =iteratorVar.next(); // Iterate through the iterator using while loop while (!result.done) { stringData += result.value + " </br>"; result = iteratorVar.next(); } function myFunction() { document.getElementById("outPut").innerHTML = "<b>The iterator elements are:</b> </br>" + stringData; } </script> </head> <body> <h1>How to Iterate an Iterator Using While Loop in JavaScript?</h1> <button onclick="myFunction()">Click here to see result</button> <p id="outPut"></p> </body> </html>