title: List data structures in JavaScript
body: <p>In <a href="http://eloquentjavascript.net/2nd_edition/preview/04_data.html#c_F3JsLaIs+m" rel="nofollow">an exercise</a> in the book <em><a href="http://eloquentjavascript.net/" rel="nofollow">Eloquent JavaScript</a></em> I need to create a list data structure (as below) based on the array [1, 2, 3]. </p>
  
  <p>The tutorial <em><a href="http://www.i-programmer.info/programming/javascript/5328-javascript-data-structures-the-linked-list.html" rel="nofollow">JavaScript Data Structures - The Linked List </a></em> shows how to do this, but I don't really understand the intention to create <code>this.start</code> and <code>this.end</code> variables inside the tutorial.</p>
  
  <pre><code>var list = {
    value: 1,
     rest: {
       value: 2,
        rest: {
          value: 3,
          rest: null
        }
     }
  };
  </code></pre>
  
  <p>I tried to solve this via the code below.</p>
  
  <pre><code>function arrayToList(array){
    var list = { value:null, rest:null};
    for(i=0; i&lt;array.length-1; i++)
       list.value = array[i];
       list.rest = list;
    return list;
  }
  </code></pre>
  
  <p>This code gives me an infinite loop of array[0]. What's wrong with my code?</p>