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:
M
Mr. Dubey     View Profile
Founder of MCQ Buddy. I just like to help others. This portal helps students in getting study material free. Share your stuff here so that others can get benefitted.