title: How to get Property value from a Javascript object
body: <p>I have a JavaScript object. </p>
  
  <pre><code>var obj = { Id: "100", Name: "John", Address: {Id:1,Name:"Bangalore"} }
  var dataToRetrieve= "Name";
  
  function GetPropertyValue(object,dataToRetrieve){
        return obj[dataToRetrieve]
  }
  var retval = GetPropertyValue(obj,dataToRetrieve)
  </code></pre>
  
  <p>This works fine. But if I try to get the value of property value of "Address.Name" ,</p>
  
  <p>Like : <code>var dataToRetrieve = "Address.Name";</code>
   it shows <code>undefined</code>.</p>
  
  <p><strong>Note :</strong> The property variable is set by user from HTML And it can be changed according to user requirement(which property value he wants).</p>
  
  <p>What I want to achieve :</p>
  
  <p>1) If <code>dataToRetrieve = "Name"</code> , it should give me <code>"John"</code>,</p>
  
  <p>2) If <code>dataToRetrieve = "Id"</code> , it should give me <code>"100"</code>, </p>
  
  <p>3) If <code>dataToRetrieve = "Address.Name"</code> , it should give me <code>"Bangalore"</code>, </p>
  
  <p>4) If <code>dataToRetrieve = "Address.Id"</code> , it should give me 1</p>
  
  <p>Plunkr Here : <a href="https://plnkr.co/edit/f5ejKuWXoNkdrDSzce51?p=preview" rel="nofollow">PLUNKR</a></p>