[英]Get names of keys in objectpath
How would I get the names of the keys, for example [800, 801] (the key names are unknown) with objectpath. 如何使用对象路径获取键的名称,例如[800,801](键名称未知)。 It is easy in jmespath: keys(@).
在jmespath中很容易:keys(@)。
"groups": {
"800": {
"short_name": "22",
"oname": "11",
"group": 8,
"title": "SS",
"name": "33",
"onames": [""],
"alt_name": False,
"waytype": 1,
"multiple": 1,
"primary": 1
},
"801": {
"short_name": "ss",
"oname": "zz",
"group": 8,
"title": "ss",
"name": "bbb",
"onames": [""],
"alt_name": False,
"waytype": 1,
"multiple": 1,
"primary": 0
},
let your object is assigned to name
variable 让您的对象分配给
name
变量
const name = { "groups": {
"800": {
"short_name": "22",
"oname": "11",
"group": 8,
"title": "SS",
"name": "33",
"onames": [""],
"alt_name": false,
"waytype": 1,
"multiple": 1,
"primary": 1
},
"801": {
"short_name": "ss",
"oname": "zz",
"group": 8,
"title": "ss",
"name": "bbb",
"onames": [""],
"alt_name": false,
"waytype": 1,
"multiple": 1,
"primary": 0
} } }
Use for loop to get the key
name as 使用for循环获取
key
名称为
for(var num in name.groups) {
console.log(num);
}
and to get the values of key 并获取键的值
for(var num in name.groups) {
console.log(name.groups[num]);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.