title: Loop over an array of json objects in JAVASCRIPT
body: <p>I'm new to Javascript, and I'm trying to loop over an array of JSON [{},{},{}, ...]</p>
  <p>I have created this function to loop on a static Array of JSON constant, but it's not working properly even after checking online and trying.</p>
  <pre><code>function saveAccount() {
      const userName = document.getElementById('user_name');
      const userPassword = document.getElementById('user_password');
      const formErrorMessage = document.getElementById('fillFormError');
      
      if(userName.value == '' || userPassword.value == '')
      {
          formErrorMessage.textContent = 'Please fill the form fields first!';
          formErrorMessage.style.color = 'red';
          event.preventDefault();
      }
      else
      {
          localStorage.setItem('userName', userName.value);
          const allUsers =  '[{&quot;username&quot;:&quot;test3&quot;,&quot;email&quot;:&quot;test3@hotmail.com&quot;,&quot;password&quot;:&quot;123&quot;},{&quot;username&quot;:&quot;test2&quot;,&quot;email&quot;:&quot;test2@hotmail.com&quot;,&quot;password&quot;:&quot;123123&quot;},{&quot;username&quot;:&quot;test1&quot;,&quot;email&quot;:&quot;test1@hotmail.com&quot;,&quot;password&quot;:&quot;456456456&quot;}]';//JSON.parse(localStorage.getItem('users'));
          for(var i = 0; i &lt; allUsers.length; i++){
              var user = allUsers[i];
              console.log(user.username);
              //alert(user[&quot;username&quot;])
              if(user.username == userName){
                  console.log('USERNAME FOUND!!!!!');
              }
          }
  
      }
  
  }
  </code></pre>
  <p>the purpose is to find if the username exists in my array of users.
  console.log(user.username); -&gt; return undifined and the .parse also returns an error.</p>