var data = {
a: 1,
b: 'string',
c: {},
d: {a: 98, b: 'str'}
}
function findKey (value, compare = (a, b) => a === b) {
return Object.keys(data).find(k => compare(data[k], value))
}
var val = data.b
findKey(val) // b
var data = {
a: 1,
b: 'string',
c: {},
d: {a: 98, b: 'str'}
}
function findKey (value, compare = (a, b) => a === b) {
return Object.keys(data).find(k => compare(data[k], value))
}
var val = data.b
findKey(val) // b