If I have only one object like below..
var json = { "key1" : "100", "key2" : "200", "key3" : "300" }
I already know that we can find the index of "key2"
like this..
var json = { "key1" : "100", "key2" : "200", "key3" : "300" }
var keytoFind = "key2";
var index = Object.keys(json).indexOf(keytoFind);
alert(index); // 1
But, now I have an array of objects in JSON like below.
var jsonArray = [{
"key1": 1000,
"key2": 1330
}, {
"key3": 900,
"key4": 600
}, {
"key5": 390,
"key6": 290
}]
I want to get the index of an object of key say "key3"
in this JSON array - which is 1.