Пример кода:
https://jsfiddle.net/kza92th7/
const fetchData = () => {
const urls = [
"https://jsonplaceholder.typicode.com/posts/1",
"https://jsonplaceholder.typicode.com/posts/2",
"https://jsonplaceholder.typicode.com/posts/3",
"https://jsonplaceholder.typicode.com/posts/4",
"https://jsonplaceholder.typicode.com/posts/5",
"https://jsonplaceholder.typicode.com/posts/6",
"https://jsonplaceholder.typicode.com/posts/7",
"https://jsonplaceholder.typicode.com/posts/8"
];
const allRequests = urls.map(url =>
fetch(url).then(response => response.json())
);
return Promise.all(allRequests);
};
fetchData().then(r => console.log(r));
Нужно вернуть вместе с результатом запроса URL
Ожидаемый результат:
[{
"url": "
https://jsonplaceholder.typicode.com/posts/1",
"json": {
"body": "quia et susc...",
"id": 1,
"title": "sunt aut facere repellat provid...",
"userId": 1
}
}, ... ]