title: Dynamically get class members names and values using Typescript or javascript
body: <p>I'm pretty new with these languages and I'm sure it's not so complicated but could not find how to walk through class instance variables dynamically.</p>
  
  <p>I'm trying to display instance's variables in a table using Angular. I'd like to write a single function that will work with any class.</p>
  
  <p>Let's say I have a workbook class:</p>
  
  <pre><code>export class workbookEntity {
      public name: string;
      public creationDate: string;
  
      constructor() {
          this.name = 'my work book name';
          this.creationDate = '2018/01/26';
      }
  }
  </code></pre>
  
  <p>And let's say I want to get the names and values of the variables of an instance of this class in another class' function:</p>
  
  <pre><code>export class showClassComponent {
      // some code here
  
      whenSubmitedInHtmlForm(className: string): void {
          // do something to walk through instance
          // with className parameter = 'workbookEntity'
      }
  
      // more code there
  }
  </code></pre>
  
  <p>How would you walk through the instance to get each variable's name and value to get something like this?</p>
  
  <pre><code>[
      {
          name: 'name',
          value: 'my work book name'
      },
      {
          name: 'creationDate',
          value: '2018/01/26'
      }
  ]
  </code></pre>