Question: I need to wait for two `fetch()` API calls and then to save data from each fetch to different window object. I found this article <https://gomakethings.com/waiting-for-multiple-all-api-responses-to-complete-with-the-vanilla-js-promise.all-method/> and tried following code to wait for the API calls:

```
Promise.all([
    fetch('https://jsonplaceholder.typicode.com/todos/1'),
    fetch('https://jsonplaceholder.typicode.com/todos/2')
]).then(function (responses) {
    // Get a JSON object from each of the responses
    return Promise.all(responses.map(function (response) {
        return response.json();
    }));
}).then(function (data) {
    // Log the data to the console
    // You would do something with both sets of data here
    console.log(data);
}).catch(function (error) {
    // if there's an error, log it
    console.log(error);
});

```

However when pasting this in browser console, the result is not being logged.

**What is wrong with the code and how to wait for both to be resolved?**

Answer: 
You can try this thing. I tested it on a fiddle and it looks like it works.

```js
Promise.all([
  fetch("https://jsonplaceholder.typicode.com/todos/1"),
  fetch("https://jsonplaceholder.typicode.com/todos/2")
]).then(responses =>
  Promise.all(responses.map(response => response.json()))
).then(data =>
  console.log(data)
).catch(err =>
  console.log(err)
);

```
My suggestion:

```js
let url = "https://jsonplaceholder.typicode.com/todos/";

async function doRequest() {
  let toDo1 = await (await fetch(url + "1")).json();
  console.log(toDo1);
  let toDo2 = await (await fetch(url + "2")).json();
  console.log(toDo2);
}

doRequest()
  .catch(err => console.log(err));
```

This way, if you need to fetch multiple items, you can use a loop inside the function.