title: Javascript: Display images out of array
body: <p>I created  a very simple script that reads out images of an array and displays them on a page.
  The array is supposed to hold more than images, but this is how I started.
  I get function undefined when I run the program
  I think this is a scope issue and the function can not be accessed when called(?)</p>
  
  <pre><code>&lt;button onclick="myFunction(images)"&gt;Try it&lt;/button&gt;
  
  &lt;script&gt;
  
  var images = [
  {img : " image1.jpg"},
  {img : "image2.jpg"}
  ]
  
  function myFunction(array) {
  
  
  for ( var i= 0; i &lt; array.length; i++){
  
  var x = document.createElement("IMG");
  x.setAttribute("src", array[i].img);
  
  document.body.appendChild(x);
  
  }
  &lt;/script&gt;
  </code></pre>