title: Javascript: Looping an object with TypeError property undefined
body: <p>I have an array of object called <code>xs</code> that store name</p>
  
  <pre><code>xs = [
      {name: "Peter"},
      {name: "Doe"},
      {name: "Parker"},
      {name: "John"}
  ];
  </code></pre>
  
  <p>and i have a function setEmptyStr that return empty string if variable is undefined</p>
  
  <pre><code>function setEmptyStr(v) {
    if(typeof v !== 'undefined'){
      return v;
    } else {
      return '';
    }
  }
  </code></pre>
  
  <p>I try to looping my array of object (with more length than the array it self), my array length is 4, i try 5. and i dont wanna use array.length;</p>
  
  <pre><code>for (var i = 0; i &lt; 5; i++) {
      console.log(setEmptyStr(xs[i].name));
  }
  </code></pre>
  
  <p>the 4 names are return successful because it is not undefined. But the 5th is return </p>
  
  <blockquote>
    <p>TypeError property 'name' is undefined.</p>
  </blockquote>
  
  <pre><code>&gt;&gt;Peter
  &gt;&gt;Doe
  &gt;&gt;Parker
  &gt;&gt;John
  </code></pre>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'name' of undefined</p>
  </blockquote>
  
  <p>I want the 5th is return an empty string. How can i do this? Is there is an error in my code?</p>
  
  <pre><code>&gt;&gt;Peter
  &gt;&gt;Doe
  &gt;&gt;Parker
  &gt;&gt;John
  &gt;&gt;""
  </code></pre>