Получилось, мож кому пригодится
window.addEventListener('load', function() {
xhttp = new XMLHttpRequest();
xhttp.open('GET', 'tt_inworld.json', true);
xhttp.send();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4) {
var listFlags = JSON.parse(xhttp.responseText);
newULFlags(listFlags);
}
}
var newULFlags = function(data) {
var divFlags = document.getElementById('flags');
var list = [];
var cols = 3;
var count = Math.ceil(data.length/cols);
var cnt = 0;
var str = '';
var items = [];
data.forEach(function(element, key) {
str = '<li style="background:url(http://test.ru/images/flags/' + element.flag + ') no-repeat;" id="' + key + '">';
if (element.SiteInWorld.length > 1) {
str += '<span>' + element.world_name + '</span>' + '<a class="name-title" href="' + element.SiteInWorld[0].link + '">' + element.SiteInWorld[0].title + '</a>' + '<a href="' + element.SiteInWorld[1].link + '">' + element.SiteInWorld[1].title + '</a>';
}
else {
str += '<a href="' + element.SiteInWorld[0].link + '">' + element.world_name + '</a>';
}
str += '</li>';
list.push(str);
cnt++;
if (cnt == count) {
var str1 = '';
str1 += list.join('');
items.push(str1);
cnt = 0;
list = [];
var mod = data.length%3;
if (mod === 1) {
count = Math.ceil(data.length/cols)-1;
}
}
});
items.forEach( function(el){
var ul = document.createElement('ul');
console.log(el);
ul.innerHTML = el;
divFlags.appendChild(ul);
});
};
});