title: Unable to understand how to use fetch in this case?
body: <p>I was solving a problem on a platform, but not getting how to do it?Can anyone help me out for this?
  Problem Description</p>
  <p>You are given the following API -</p>
  <blockquote>
  <p>GET /api/comments</p>
  <p>This will return a list of all comments. A comment object contains the following information</p>
  <p>userId - ID of the user who commented</p>
  <p>data - comment data</p>
  <p>Given a userId, return an Array of comment data of all the comments by the given user.</p>
  <p>Note
  Apart from .json(), don’t use any other methods on the response object returned from fetch() call. This can cause your tests to fail.</p>
  <p>Input - userId - the user id whose comment is to be returned.</p>
  <p>Output - A list of comments by the given user id</p>
  <p>Sample input 1 -</p>
  <p>userId = 1</p>
  <p>Sample API response</p>
  <pre><code>comments = [
  {
    'userId': '1',
    &quot;data&quot;: 'This looks slick!'
  },
  {
    'userId': '2',
    &quot;data&quot;: 'I think this can be improved.'
  },
  {
    'userId': '1',
    &quot;data&quot;: 'What kind of improvement?'
  }]
  </code></pre>
  <p>Sample output 1 - ['This looks slick!', 'What kind of improvement?']</p>
  </blockquote>
  <p>Below code that we have to complete</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>// TODO - Implement getCommentsByUserId() function
  async function getCommentsByUserId(userId) 
  {
      let v=await fetch(`/api/comments/${userId}`,{})
      .then(response=&gt;)
  
  }
  
  // ----------- Don't modify -----------
  const mockFetch = (url, responseData) =&gt; {
      const mockJsonPromise = Promise.resolve(responseData);
      const mockFetchPromise = (callUrl) =&gt; {
          if (url === callUrl) {
              return Promise.resolve({
                  json: () =&gt; mockJsonPromise
               });
          } else {
              return Promise.reject('404: No such url')
          }
      }
      global.fetch = mockFetchPromise;
  }
  
  const successResponse = [
      {
          'userId': '1',
          "data": 'This looks slick!'
      },
      {
          'userId': '2',
          "data": 'I think this can be improved.'
      },
      {
          'userId': '1',
          "data": 'What kind of improvement?'
      }];
  mockFetch('/api/comments', successResponse);
  
  module.exports = getCommentsByUserId;
  // ----------- Don't modify -----------
  
  getCommentsByUserId("1").then((res) =&gt; {
    console.log(res);
  });</code></pre>
  </div>
  </div>
  </p>