In this post we will see while loop in JavaScript. While loop keep working until the condition is true. As soon as the condition is false it stops.
For example we have taken one array here and we will push the values in this array with the help of while loop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>While Loop in JavaScript</title>
</head>
<body>
<script>
var myArray = [];
var i = 0;
while(i < 5){
myArray.push(i);
i++;
}console.log(myArray);
</script>
</body>
</html>