Open this example in the interactive library
Source code
const codes = { red: "R", green: "G" };
console.log(
Object.fromEntries(Object.entries(codes).map(([k, v]) => [v, k])),
);
Sample output
{ R: 'red', G: 'green' }
Open this example in the interactive library
const codes = { red: "R", green: "G" };
console.log(
Object.fromEntries(Object.entries(codes).map(([k, v]) => [v, k])),
);
{ R: 'red', G: 'green' }