Confused about iterating nested objects
<p>so I have the following object: </p>

<pre><code>{ err:
  { message: 'Validation failed',
    name: 'ValidationError',
    errors: 
     { username: 
        { properties: [Object],
          message: 'Path `username` is required.',
          name: 'ValidatorError',
          kind: 'required',
          path: 'username',
          value: '' } } } }
</code></pre>

<p>I am trying to iterate over <code>err.errors</code> and push for example <code>err.errors.username.message</code> into an array:</p>

<pre><code>for(var error in err.errors){
  messages.push(error.message);
}
</code></pre>

<p>Doing this is just pushing null into my <code>messages</code> array. So to troubleshoot I have tried to <code>console.log(typeof error);</code> which gives me a <code>string</code>. This is what is confusing because, when I call <code>typeof</code> on <code>err.errors.username</code> it outputs <code>object</code>, yet calling it inside of the loop it produces <code>string</code>...</p>

<p>So what is going on here?</p>