title: How to access the properties of this json object?
body: <p>Lets say I've a JSON object like this stored in a file maj.json, which I import into my main.js file like this</p>
  
  <p>maj.json</p>
  
  <pre><code>{
    "prop1": {
      "p1": 12,
      "p2": "qwer"
    },
    "prop2": {
      "p1": 34,
      "p2": "asdf"
    },
    "prop3": {
      "p1": 56,
      "p2": "zxcv"
    }
  }
  </code></pre>
  
  <p>In main.js</p>
  
  <pre><code>var js = require("./maj.json");
  </code></pre>
  
  <p>Now I've an array like this</p>
  
  <pre><code>var prop = ["prop2", "prop3"];
  </code></pre>
  
  <p>How can I get the properties listed in say, array prop from js. I tried like this, but it's not working. I'm getting <strong>undefined</strong> result with this approach.</p>
  
  <pre><code>for(str in prop) {
      console.log(js.prop[str]);
  }
  </code></pre>
  
  <p>output for this :</p>
  
  <pre><code>undefined
  undefined
  </code></pre>
  
  <p>How can I do something like this in the right way?</p>
  
  <p><strong>EDIT</strong>
  More importantly how can i do this for inner properties like access prop2.p2 etc. dynamically, i.e both prop2 and p2 are given dynamically?</p>