[英]How can I access the keys from the below local json file?
I want to access all the keys present in the local json file.我想访问本地 json 文件中存在的所有密钥。 When I am using Object.keys(data) it is returnning the 0. I had checked the output in the console,by default the output of json is mapped to 0. So please let me know how can I access the keys. When I am using Object.keys(data) it is returnning the 0. I had checked the output in the console,by default the output of json is mapped to 0. So please let me know how can I access the keys.
public ngOnInit(){
this._logger.info("Header Mapping Component Initialized");
this.httpClient.get("applauncher/input.json").subscribe(res=>{
this.products=res;
this.keys=Object.keys(this.products);
console.log("Mapping data",this.keys);
});
input.json
[
{
"College1": [
[
"Studname1"
],
[
"Studname2"
]
],
"College2": [
[
"Stud1"
]
],
}
] ]
You can simply do你可以简单地做
const list = [{ "College1": [ [ "Studname1" ], [ "Studname2" ] ], "College2": [ [ "Stud1" ] ], }] const keys = list.map(item => Object.keys(item)); console.log(keys[0]);
Output => ["College1", "College2"] Output => [“College1”,“College2”]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.