I'm having JSON data source as like below,
var datasource = [{name: 'x', age: 20, address: 'yyyy'},
{name: 's', age: 30, address: 'zzzz'}]
in this fields(name, age, address) will be dynamically changed as per the user. Here i want to iterating the records and its values.
I am trying like this and facing exception,
let keys: Object[] = Object.keys(datasource[0]);
let dlen: number = datasource.length as number;
while (dlen--) {
let kLn: number = keys.length;
while (kLn--) {
let key: string = keys[kLn] as string;
let isPropContains: boolean = false;
let value: string;
if(datasource[dlen][key]) {
isPropContains = true;
value = datasource[dlen][key] as string;
}
}
}
Here, how can i access object property (datasource[dlen][key]) like we accessing in javascript index type?
Note: I want to achieve this without using type 'any' and 'eval' in typescript. Need strongly typed.
I have checked this How do I dynamically assign properties to an object in TypeScript? but it doest satisfied my requirement. Because they using 'any' type, i want to achieve without using 'any' or 'eval'.