Javascript html table get clicked cell value and column(th) ID

i am trying to get a clicked Table Cell value and corresponding Column ID (th.id)
i need in the $msg the following.

  • Clicked Cell Value (easy (e.target.innerHTML)
  • Get the cellIndex from the cell (td) (easy e.target.cellIndex)
  • corresponding column (th) ID for the same e.target.cellIndex
    *** when i comment the foreach the code work.
    the foreach apparently not working
    Please help
    function onTableCellClicked(e){
     //  alert('table cell clicked value ='+e.target.innerHTML);
       if(e.target.innerHTML && window.chrome.webview){
        $ind=e.target.cellIndex
        $Msg=e.target.innerHTML
       var TTH = document.getElementById('NGTable1 th');
       TTH.forEach(function(th) {
         if (th.cellIndex==$ind){$Msg=$Msg+'|'+th.id}
        })
       window.chrome.webview.postMessage($Msg);
     }  
   }