I need to find the key of last property starting with a string
JSON:
var data = {
"admin": "peterson",
"worker": "peter napier",
"housekeeper": "peterson",
"worker": "richard Ben",
"executive": "richard parker",
"executive": "peter alp",
"housekeeper": "richard johny",
"admin": "richardson"
};
I have to write an algorithm which will return the key corresponding to the last occurence of value starting with a string.
Ex: I need to get admin
if I call findKey("richard")
I need to get executive
if I call findKey("peter")
I have iterated the object using simple for loop as this
for (var key in yourobject) {
console.log(key, yourobject[key]);
}
But I like to know the fastest way of iterating this as my scenario has more than 100000 property.