Currently, I am attempting to loop through a set of data in order to populate my table. The data is being retrieved from my controller (CI3) and I have tried using JSON encoding like so:
{"1":{"2":["SOP","SOP 16","YES"]},"3":{"7":["SIP","SIP 12","YES"]},"4":{"18":["SAP","SAP 12","YES"]}}
This is the snippet of Javascript code where I attempted to loop through the data:
const table_show = (data) => {
console.log(data)
document.getElementById('mabody').innerHTML = '';
let str_table = '';
data.forEach((ir_labs_1,key_ir_1) =>{
str_table += '<tr id="data_ir_'+key_ir_1+'"><td>POSM</td><td>' + ir_labs_1 + '</td><td id="osa_'+key_ir_1+'">0</td></tr>';
})
document.getElementById('mabody').innerHTML = str_table;
}
However, upon running this code, I encounter the following error:
TypeError: data.forEach is not a function
I am uncertain as to what is causing this issue and how to resolve it. Can anyone provide guidance on how to rectify this problem?