Thumb

JavaScript for loop

1/22/2020 12:34:15 AM

JavaScript has for loop. When we want work with collection or array then some time use the for loop. But looping mechanism means when we work repeat by the condition then we use loop in JavaScript.  JavaScript loop is very important. Basically, for loop have three part one is Initializing another is conditional and last part is increment or decrement. Now given bellow the example code and explain the code:

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<script type="text/javascript">
  // JavaScript for loop
    var myName="Farhan Sakib Jesy";
for (var i = 1; i <= 5; i++) {
  console.log(myName);
}
var name = ["Jesy", "Reza", "Tofile"];
for (var i = 0; name.length; i++) {
  console.log(name[i]);
}
</script>
</body>
</html>

In this part we print the name and then we print the array using for-loop. This loop will use also another purpose also your need.