title: JavaScript - Loop through Object to find Specific Key Value
body: <p>I have a file called <code>contentful.json</code> which is stored in the root of my directory.</p>
  
  <p>This is what that file looks like:</p>
  
  <p><code>[{
      "URL": "/force",
      "SpaceID": "2g1335I9GYQCKwmQYCuSSI"
  }, {
      "URL": "/heroku",
      "SpaceID": "2g1335I9GYQCKwmQYCuSSI"
  }, {
      "URL": "/slack",
      "SpaceID": "2g1335I9GYQCKwmQYCuSSI"
  }, {
      "URL": "/contentful",
      "SpaceID": "2g1335I9GYQCKwmQYCuSSI"
  }, {
      "URL": "/openShift",
      "SpaceID": "2g1335I9GYQCKwmQYCuSSI"
  }]</code></p>
  
  <p>I then have a file called <code>contentful.js</code>.</p>
  
  <p>Which looks like this:</p>
  
  <pre><code>const fs = require('fs');
  
  let obj;
  
  fs.readFile('./contentful.json', 'utf8', (err, jsonData) =&gt; {
    if (err) throw err;
    obj = JSON.parse(jsonData);
  
    // Method One
    for (let i = 0, l = obj.length; i &lt; l; i++) {
      console.log(obj.URL);
      // ...
    }
  
    // Method Two
    Object.keys(obj).forEach((key) =&gt; {
      if (key.url === '/heroku') {
        console.log(key.SpaceID);
      }
    });
  });
  </code></pre>
  
  <p>What I am trying to do is read the <code>contentful.json</code> file from the <code>contentful.js</code> file. Which works.</p>
  
  <p>Then I am trying to loop through that file and find a specific value. </p>
  
  <p>E.G loop through the JSON object, and where URL equals a dynamic value (/force) return me the SpaceID.</p>
  
  <p>So this JSON object could be <strong>n</strong> big. I have attempted two solutions but don't think I am quite their yet. </p>
  
  <p>I need to input a URL into the <code>contnetful.js</code> file and if that URL matches the URL in the <code>contnetful.json</code> file I would like it to return that SpaceID.</p>