JavaScript For In Loop Example

JavaScript for in loop execute block of code for each element of an array (or each property of an object).

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>JavaScript for in array</title>
</head>
<body>
<pre>  <!-- Use pre element for work document.writeln() method -->
<script>
  var arr = ['a','b','c'];
  for (var key in arr) {
    document.writeln(key +" : "+ arr[key]);
  }
</script>
</pre>
</body>
</html>

Run it...   »

Example Result