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).


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

Run it...   »

Example Result