获取JSON中键的索引 [英] Get index of a key in json
本文介绍了获取JSON中键的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个像这样的json:
I have a json like so:
json = { "key1" : "watevr1", "key2" : "watevr2", "key3" : "watevr3" }
现在,我想知道一个键的索引,在json中说"key2"-为1.有没有办法?
Now, I want to know the index of a key, say "key2" in json - which is 1. Is there a way?
推荐答案
为时已晚,但它可能既简单又有用
Its too late, but it may be simple and useful
var json = { "key1" : "watevr1", "key2" : "watevr2", "key3" : "watevr3" };
var keytoFind = "key2";
var index = Object.keys(json).indexOf(keytoFind);
alert(index);
这篇关于获取JSON中键的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文