title: Making keys and append my console log result to html textboxes
body: <p>My target is how can  i append my data result to html textbox? What i have tried so far is this (Please see the codes below). I encountered an error while making it:</p>
  <blockquote>
  <p>Uncaught TypeError: Cannot read properties of undefined (reading 'forEach')</p>
  </blockquote>
  <p>This is my result that i need to append</p>
  <p><a href="https://i.stack.imgur.com/LC8h9.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LC8h9.png" alt="enter image description here" /></a></p>
  <p>There something wrong my foreach and i'm getting confused. Any help will be appreciated. Thank you.</p>
  <p>html:</p>
  <pre><code> &lt;div id=&quot;result&quot;&gt; &lt;/div&gt;
  </code></pre>
  <p>ajax:</p>
  <pre><code>let result = [];
            
    function newCombine(data, difference) {
    let nonMatched = [...data]
    const groups = {}
  
    for (let i = 0; i &lt; nonMatched.length - 1; i++) {
      const first = nonMatched[i]
  
      inner: for (let j = nonMatched.length - 1; j &gt; i; j--) {
        const second = nonMatched[j]
        const delta = Math.abs(first.weight - second.weight)
  
        if (delta &lt;= difference &amp;&amp; first.entryName !== second.entryName) {
          const groupKey = `${first.weight}_${second.weight}`
          groups[groupKey] = [first, second]
          nonMatched = nonMatched.filter(
            obj =&gt; obj.entryID != first.entryID &amp;&amp; obj.entryID != second.entryID
          )
          i = -1
          break inner
        }
      }
    }
    return { ...groups, ...nonMatched }
  }    
  
  
  
  $(document).ready(function() {
  
  
  var entry_list =$('#entry_list1').DataTable({ 
        
   
          &quot;ajax&quot;: {
                &quot;url&quot;: &quot;&lt;?php echo site_url('report/controlget')?&gt;&quot;,
              &quot;type&quot;: &quot;get&quot;,
              
             success: function(data) {
                  
              const source = data;
               const a = newCombine(source, 15);
              
              console.log(a);
              
              
              //this is the start of my data result appending to the html
              
              
                      var keys = Object.keys(a)
              
                  
          
   var count = 0;               
  for (var i = 0; i &lt; keys.length; i++) {
  
  
    result[keys[i]].forEach(function(val) {
    var length_ = val.length;
      val.forEach(function(value, index) {
      
  var idaa = value.eventID ; 
    
  
  
    
    
  if (idaa == eventID){
      if (length_ == 2) {
  
        var entryIDs = index == 0 ? &quot;entryIDM[]&quot; : &quot;entryIDW[]&quot;
        var players = index == 0 ? &quot;playerM[]&quot; : &quot;playerW[]&quot;
        var weights = index == 0 ? &quot;weightM[]&quot; : &quot;weightW[]&quot;
        var lightBands = index == 0 ? &quot;lightBandM[]&quot; : &quot;lightBandW[]&quot;
        html += `&lt;input type=&quot;text&quot; name=&quot;${entryIDs}&quot; value=&quot;${value.entryID}&quot;&gt; 
                   &lt;input type=&quot;text&quot; name=&quot;${players}&quot; value=&quot;${value.player}&quot;&gt;
                   &lt;input type=&quot;text&quot; name=&quot;${weights}&quot; value=&quot;${value.weight}&quot;&gt;
                   &lt;input type=&quot;text&quot; name=&quot;${lightBands}&quot; value=&quot;${value.lightBand}&quot;&gt;
                   &lt;input type=&quot;text&quot; name=&quot;eventID&quot; value=&quot;${value.eventID}&quot;&gt;
         
                
                  
                
                  
  `
  
        }
        }
        
      })
    })
  }
  
  
  document.getElementById(&quot;result&quot;).innerHTML = html //add html to div
              
              
              
              },
              }
      
   
      });
      
   });
  </code></pre>
  <p>Controller:</p>
  <pre><code>  public function controlget()
      {
          
          $list = $this-&gt;reports-&gt;getallentry();
          echo json_encode( $list );
          
      }
      
      Model:
  
   public function getallentry()
      
      {
          $this-&gt;db-&gt;select('entryID,entryName,weight');
          $this-&gt;db-&gt;from('entry');
          $query = $this-&gt;db-&gt;get();
          return $query-&gt;result();
          
      }
  </code></pre>