I have a json like so:
json = { \"key1\" : \"watevr1\", \"key2\" : \"watevr2\", \"key3\" : \"watevr3\" }
Now, I want to know the index of a key
Try this
var json = '{ "key1" : "watevr1", "key2" : "watevr2", "key3" : "watevr3" }'; json = $.parseJSON(json); var i = 0, req_index = ""; $.each(json, function(index, value){ if(index == 'key2'){ req_index = i; } i++; }); alert(req_index);