按值查找对象键

Look up object keys by value

Object = {"o":"s","e":"w"}

如果我有这个对象,有没有办法对其进行反向查找? 类似于:

Object.invert()["s"]
> "o"

您想还原 key/value 映射。

var test = {a: "b", c: "d"}
var reverted = {}
for(var key in test) {
    reverted[test[key]] = key
}