function invert(obj){ for (let k in obj) { let name = obj[k]; obj[name] = k; delete obj[k]; } return obj; } const obj = { first: "fs", second: "fw" } let obj2 = invert(obj) console.log(obj2.fs) console.log(obj.fw)