I want to make a loop in JS that creates a div for every "id" on my Array. For example, I have the following:
var Boletins =
{
id:1, items:
[
{
"#": "1",
"Data": "19 a 25 de Março de 2021",
"Região": "região de Trás-Os-Montes e Alto Douro",
"Niveis": "muito elevados",
"PoleneArvore": "cipreste, pinheiro",
"PoleneErva": "urtiga, gramíneas"
}],
id:2, items:
[
{
"#": "10",
"Data": "26 de Março a 1 de Abril de 2021",
"Região": "região de Trás-Os-Montes e Alto Douro",
"Niveis": "muito elevados",
"PoleneArvore": "plátano, cipreste, pinheiro, carvalhos"
}
]
}
Based on the id, I want to make a loop that creates a Div in HTML for each entry of "id" present on the array. In my code it reaches id:14 but I only pasted until id:2. This is my code to create the divs:
htmlText += '<div class="divBoletim">';
htmlText += '<p>Created Div</p>';
htmlText += '</div>';
$('body').append(htmlText);
I'm just not understanding how I would make a loop for each id entry. Thanks in advance for those who help.
idanditemsto it's own object:Boletins = [{id: .., items: []}, {id: , items: []}...]itemsarray don't use an array just have the object as the value ofitems.