onlyforbopi
9/24/2018 - 12:29 PM

JS.Basics.Arrays.IteratingArraysTwoParameters

JS.Basics.Arrays.IteratingArraysTwoParameters

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

persons.forEach(function(p, index) {
  document.body.innerHTML += p.name + ", age " + p.age + 
                             ", at index " + index + " in the array<br>"; 
});

JS.Basics.Arrays.IteratingArraysTwoParameters

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 names, ages and indexes have been generated dynamically 
      by iterating on an array using the <code>forEach</code> method with 2 parameters in the callback function</b>
  </p>
</body>
</html>