title: Javascript: How to Get Object property using Array of string?
body: <p>How do i get object property using array of string (name of properties)? (the last element in array is the inner property of object)</p>
  
  <p>See the code below:</p>
  
  <p>Handy way:</p>
  
  <pre><code>let myObject = {
      "property": {
          "subproperty": {
              "targetproperty": "Hi, We done it!"
          }
      }
  };
  let myString = "property:subproperty:targetproperty";
  let parts = myString.split( ":" );
  console.log( myObject[ parts[ 0 ] ][ parts[ 1 ] ][ parts[ 2 ] ] ); // Output: "Hi, We done it!"
  </code></pre>
  
  <p>Eval way:</p>
  
  <pre><code>let myObject = {
      "property": {
          "subproperty": {
              "targetproperty": "Hi, We done it!"
          }
      }
  };
  let myString = "property:subproperty:targetproperty";
  let parts = myString.split( ":" );
  let code = "myObject";
  for ( let i = 0; i &lt; parts.length; i++ ) {
      code += "['" + parts[ i ] + "']";
  }
  code += ";";
  console.log( code );
  console.log( eval( code ) ); // Output: "Hi, We done it!"
  </code></pre>
  
  <p>Eval is evil. so i need a cleaner way to do it.</p>
  
  <p>How do i do it without eval and handy job?</p>