从嵌套对象中选择密钥
问题描述:
我在这里有一种情况。我在这里有一个对象,它嵌套在另一个对象中,在这里我想选择键。对象如下所示从嵌套对象中选择密钥
var x={
"_shards": {
"total": 10,
"successful": 5,
"failed": 0
},
"_all": {
"primaries": {
"indexing": {
"index_total": 4,
"index_time_in_millis": 5,
"index_current": 0,
"delete_total": 0,
"delete_time_in_millis": 0,
"delete_current": 0
}
},
"total": {
"indexing": {
"index_total": 4,
"index_time_in_millis": 5,
"index_current": 0,
"delete_total": 0,
"delete_time_in_millis": 0,
"delete_current": 0
}
}
},
"indices": {
"get56_name": {
"primaries": {
"indexing": {
"index_total": 4,
"index_time_in_millis": 5,
"index_current": 0,
"delete_total": 0,
"delete_time_in_millis": 0,
"delete_current": 0
}
},
"total": {
"indexing": {
"index_total": 4,
"index_time_in_millis": 5,
"index_current": 0,
"delete_total": 0,
"delete_time_in_millis": 0,
"delete_current": 0
}
}
}
}
}
如何选择键即“get56_name”作为答案。我不想要的价值,我想选择关键我怎么能得到它?
答
这将在排列键的返回第一个键,像"get56_name"
Object.keys(x["indices"])[0]
希望这是你问
答
尝试一下这个:
var your_variable = Object.keys(x.indices)[0];
你是什么意思“的意思是我不想要价值?“那么你将如何处理对象呢? – 2014-09-23 06:09:11
你想要什么输出 – 2014-09-23 06:13:06
可能重复[如何列出JavaScript对象的属性](http://*.com/questions/208016/how-to-list-the-properties-of-a-javascript-object ) – JJJ 2014-09-23 06:13:57