如何使用TypeScript迭代对象并能够访问键和值?
我的JSON对象看起来像这样:
{
"clients": {
"123abc": {
"Forename": "Simon",
"Surname": "Sample"
},
"456def": {
"Forename": "Charlie",
"Surname": "Brown"
}
}
}
客户端需要填写的对象是由客户端模型组成的,看起来像这样:
export class ClientModel {
id:string;
forename:string;
surname:string;
constructor(
private id:string,
private forename:string,
private surname:string
) {
this.id = id;
this.forename = forename;
this.surname = surname;
}
}
Object.keys
。对于大多数情况来说,它与https://dev59.com/t2Eh5IYBdhLWcg3wNxPM#22658584相同,更简单且更常见。 - basaratObject.keys
更合适,谢谢。 - Nikos Paraskevopoulos