title: Dynamic JSON creation using jQuery
body: <p>I am new to JSON and tried the below example to see the results but it returns an empty array in the console. Any suggestions?</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function createJSON() {
    var obj = [];
    var elems = $("input[class=email]");
    
    for (i = 0; i &lt; elems.length; i += 1) {
      var id = this.getAttribute('title');
      var email = this.value;
      tmp = {
        'title': id,
        'email': email
      };
      obj.push(tmp);
    }
    
    var jsonString = JSON.stringify(obj);
    console.log(jsonString);
  }
  
  createJSON();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;</code></pre>
  </div>
  </div>
  </p>