You are here: Home / Topics / For Loop Iteration In JavaScript

For Loop Iteration In JavaScript

Filed under: JavaScript on 2023-08-06 22:39:18

In this example, we will see for loop iteration. We have taken one blank array. We will push the values in this array using for loop. Below is the complete example of this action.

<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <title>For Loop in JavaScript</title>
</head>
<body>
   <script>
       var myArray = [];

       for(let i = 0; i<=5; i++){
           myArray.push(i);
       }

       console.log(myArray);
       //this will print
       //[0,1,2,3,4,5]
   </script>
</body>
</html>

 

Hope you enjoyed this article. You can learn Javascript Mcqs in this website to practice questions.

About Author:
S
Shyam Dubey     View Profile
If you are good in any field. Just share your knowledge with others.