onlyforbopi
9/24/2018 - 12:32 PM

JS.Basics.Arrays.IteratingArraysForLoop.js

JS.Basics.Arrays.IteratingArraysForLoop.js

var persons = [
  {name:'Michel', age:51},
  {name:'Henri', age:20},
  {name:'Francois', age:29},
  {name:'John', age:69}
];

for(var i = 0; i < persons.length; i+=2) {
  var p = persons[i]; // current element
  
  document.body.innerHTML += p.name + "<br>"; 
}

JS.Basics.Arrays.IteratingArraysForLoop.js

A Pen by Pan Doul on CodePen.

License.

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Draw a monster in a canvas</title>
</head>
<body>
  <p>
    <b>These nameshave been generated dynamically 
      by iterating 2 elements by 2 on an array using a <code>for</code> loop.</b>
  </p>
</body>
</html>