any JQuery pros here who can help me? var requests = Array();
for(var i=0; i<numOfCalls; i++){
var request = $.get('/wp-json/wp/v2/posts?_embed&per_page=100&page='+(i+1));
requests.push(request);
} $.when.apply($,requests).done(function(){
console.log(arguments);
}) $.when.apply($,requests).done(function(){
for(var i=0; i<arguments.length; i++){
for(var x=0; x<arguments[i][0].length; x++){
final.push(arguments[i][0][x]);
}
}
console.log(final); //HERE ARE OUR RECORDS
}
Something like this? const requests = Array.from({length: numOfCalls}, (_, i) => { return fetch(`/wp-json/wp/v2/posts?_embed&per_page=100&page=${i + 1}`) .then((response) => response.json()); }); Promise.all(requests).then((posts) => { console.log(posts); const final = posts.flatMap((post) => post[0]); console.log(final); });
Обсуждают сегодня