Get index of a key in json

前端 未结 6 543
北恋
北恋 2021-01-31 03:48

I have a json like so:

json = { \"key1\" : \"watevr1\", \"key2\" : \"watevr2\", \"key3\" : \"watevr3\" }

Now, I want to know the index of a key

6条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 04:27

    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);
    

提交回复
热议问题