blog icon indicating copy to clipboard operation
blog copied to clipboard

如何翻转对象中的键和值?

Open wuxianqiang opened this issue 5 years ago • 0 comments

const myObj = {
  a: "aKey",
  b: "bKey",
  c: "cKey"
}

const reversed = {};
for (key in myObj) {
  reversed[myObj[key]] = key;
}

wuxianqiang avatar Jan 09 '20 02:01 wuxianqiang