The problem is simple, in javascript I can have an object as this one
var obj={
par1:'value1',
par2:'value2'
}
And I can access to the values in this ways obj['par1'] is it possible to do the same thing in TypeScript with a class like this:
export class obj{
par1:string;
par2:string;
}
this.obj['par1']=value1
Update
This is the Documents class
export class Documents {
par1: string
par2: string
constructor(par1: string,
par2: string
){
this.par1=par1
this.par2=par2
}
}
And this is my attempt:
private docs:Documents[]=new Documents[
new Documents('value1','value2'),
new Documents('value3','value4')
];
sort(ordertype:string,property:string){
for(let doc of this.docs){
for(let field in doc)
console.log(doc[field])
}
}
And this is an error:
[ts] Element implicitly has an 'any' type because index expression is not of type 'number'.
I've even tried to cast it to string but nothing.
Update 2
I've saw the error, I corrected it, the code above is correct and works.