How to get the values of key value pairs defined in an interface in typescript -
interface Person {
[Id: string]: PersonConfig
}
interface PersonConfig {
name: string,
age: number
}
const people: Person[] = [
{
"p1": {
name: "abcd",
age: 20
}
},
{
"p2": {
name: "efgh",
age: 78
}
}
];
Object.entries(people).forEach(([key, value]) => {
console.log(value);
});
I get the result as -
{ p1: { name: 'abcd', age: 20 } }
{ p2: { name: 'efgh', age: 78 } }
Now, I want the values of key and values separately. I do not see a way other than providing key values by myself (console.log(value["p1"])).
Expecting the output as :
console.log(value.Id + "-" + value.PersonConfig);