I have a json like so:
json = { "key1" : "watevr1", "key2" : "watevr2", "key3" : "watevr3" }
Now, I want to know the index of a key, say "key2" in json - which is 1. Is there a way?
To get the index from a JSON object with value with JavaScript, we can use the array findIndex method.
You can index JSON data as you would any data of the type that you use to store it. In particular, you can use a B-tree index or a bitmap index for SQL/JSON function json_value , and you can use a bitmap index for SQL/JSON conditions is json , is not json , and json_exists .
Keys must be strings, and values must be a valid JSON data type: string. number.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With