I'm looking to iterate a JSON array and print the results inside a row (3 equal columns). The actual method don't respect the logic behind bootstrap, so how can I tell JS to include only 3 elements then clone a similar div. Here's a runnable code so you can have a feel of the issue. Should be viewed on large screens. Thanks.
var url = "https://api.openaq.org/v1/countries?order_by=count&sort=desc";
$.getJSON(url, function (data) {
$.each(data.results, function(i, result) {
$('#data').append(
$('<h2>').text(result.name),
$('<div>').text("Code = " + result.code),
$('<div>').text("Score = " + result.count),
$('<hr>').text(" "),
);
});
});
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
<div class="container">
<h1></i>Open, real-time and historical air quality data</h1>
<hr>
<div class="row" style="background-color: #ddd">
<div class="col-md-4" id="data" style="background-color: #fe8000" ></div>
</div>
<h6 style="padding-bottom: 25px">Source: This data is licensed under the Creative Commons Attribution 4.0 Generic License. It is attributed to OpenAQ.
The software is licensed as below with The MIT License.</h6>
</div>
<script src="https://code.jquery.com/jquery-3.2.1.js"
integrity="sha256-DZAnKJ/6XZ9si04Hgrsxu/8s717jcIzLy3oi35EouyE="
crossorigin="anonymous"></script>