title: Using forEach in Javascript with a django json response
body: <p><strong>&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;EDIT&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;</strong></p>
  <p>I found the answer <a href="https://stackoverflow.com/questions/53275405/typeerror-data-foreach-is-not-a-function">here</a>. I need to parse the data using JSON.parse() before going into forEach</p>
  <p><strong>&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;&lt;&gt;</strong></p>
  <p>I have a json response from django and I'm trying to display each item in the json response as its own div using javascript.</p>
  <p>The json response is as follows:</p>
  <pre><code>[{&quot;model&quot;: &quot;network.posts&quot;, &quot;pk&quot;: 1, &quot;fields&quot;: {&quot;user&quot;: 1, &quot;post&quot;: &quot;hi&quot;, &quot;timestamp&quot;: &quot;2020-11-10T21:24:51.118Z&quot;}}, {&quot;model&quot;: &quot;network.posts&quot;, &quot;pk&quot;: 2, &quot;fields&quot;: {&quot;user&quot;: 1, &quot;post&quot;: &quot;My first post!&quot;, &quot;timestamp&quot;: &quot;2020-11-10T21:25:07.893Z&quot;}}, {&quot;model&quot;: &quot;network.posts&quot;, &quot;pk&quot;: 3, &quot;fields&quot;: {&quot;user&quot;: 2, &quot;post&quot;: &quot;This is my 3rd post :)&quot;, &quot;timestamp&quot;: &quot;2020-11-10T22:43:23.383Z&quot;}}, {&quot;model&quot;: &quot;network.posts&quot;, &quot;pk&quot;: 4, &quot;fields&quot;: {&quot;user&quot;: 2, &quot;post&quot;: &quot;This is my 3rd post :)&quot;, &quot;timestamp&quot;: &quot;2020-11-10T22:44:34.421Z&quot;}}, {&quot;model&quot;: &quot;network.posts&quot;, &quot;pk&quot;: 5, &quot;fields&quot;: {&quot;user&quot;: 2, &quot;post&quot;: &quot;This is my 3rd post :)&quot;, &quot;timestamp&quot;: &quot;2020-11-10T22:47:17.896Z&quot;}}]
  </code></pre>
  <p>That comes from a django view which is:</p>
  <pre><code>def get_posts (request):
  
      # Get list of posts
      posts = Posts.objects.all()
  
      if request.method == &quot;GET&quot;:
          return JsonResponse(serializers.serialize('json', posts), safe=False)
  </code></pre>
  <p>For now I'm just trying to console log each 'post' using javascript. Here's what I have so far:</p>
  <pre><code>// Load all posts
  
  fetch(`/posts`)
  .then(response =&gt; response.json())
  .then(data =&gt; {
    console.log(data);
  
  });
  </code></pre>
  <p>That works, but it logs the whole json response. What I want to do is chop it up so each post is logged separately, but I can't work it out! I tried using ForEach like this:</p>
  <pre><code>// Load all posts
  
  fetch(`/posts`)
  .then(response =&gt; response.json())
  .then(data =&gt; {
    console.log(data);
  
    data.forEach( () =&gt; {
      console.log(data);
    });
  });
  </code></pre>
  <p>But I keep getting an error of <code>Uncaught (in promise) TypeError: data.ForEach is not a function</code></p>
  <p>How do I fix this?</p>