I am working with JSON data with for-of loop how can I do and one more point what if the last entry is single like
my js code:
var counter=0,temp=2;
function load() {
fetch("https://jsonplaceholder.typicode.com/photos")
.then(function (response) {
return response.json();
})
.then((response) => {
for (var [index,value] of response.entries()) {
alert(value);
if(index < temp){
var wrapper = document.createElement("div");
var img = document.createElement("img");
var title = document.createElement("h6");
img.src = value.url;
title.innerHTML = value.title;
wrapper.setAttribute("class", "wrapper");
img.setAttribute("class", "img-class");
title.setAttribute("class", "title");
wrapper.appendChild(img);
wrapper.appendChild(title); document.getElementById("main").appendChild(wrapper);
index++;
}else{
index = index;
counter = counter + 2;
temp=counter;
break;
}
}
});
}
}