I'm trying to find key of object which is containing my value.
There is my object:
var obj = {}
obj["post1"] = {
"title": "title1",
"subtitle": "subtitle1"
}
obj["post2"] = {
"title": "title2",
"subtitle": "subtitle2"
}
And now, I'm trying to get object key of value "title2"
function obk (obj, val) {
const key = Object.keys(obj).find(key => obj[key] === val);
return key
}
console.log(obk(obj, "title2"))
Output:
undefined
Desired output:
post2
obj[key].title === val