title: how to dynamically add value to object in an array of objects in TypeScript?
body: <p>How do I add value to object in an array of objects in Typescript? </p>
  
  <p>Say I have an array of object like this:</p>
  
  <pre><code>[{name:'John',age:20}, {name:'Sam',age:26}, {name:'Will',age:2}]
  </code></pre>
  
  <p>What I want is dynamically generated property in each object of array as this:</p>
  
  <pre><code>[{name:'John',age:20, value:'John 20'}, {name:'Sam',age:26, value:'Sam 26' }, {name:'Will',age:2, value:'Will 2'}]
  </code></pre>
  
  <p><strong>This is what I tried:</strong> I have a created a model for type checking and created a method in it which will return the value. </p>
  
  <pre><code>export class Names {
      name: string;
      age: number;
      constructor() {
      }
      getConcat() {
          return this.name + ' ' + this.age;
      }
  }
  </code></pre>
  
  <p>Although when I get data from server of type <code>Names[]</code>, I am not able to fetch the dynamically generated value. I am trying to get values like this: </p>
  
  <pre><code>this.somevariable:Names[]=[];  //declarartion
  this.somevariable[0].getConcat() // inside a method after api call
  </code></pre>
  
  <p>How do I do that? Any help would be much appreciated. Thanks! </p>