Click here to Skip to main content
15,891,567 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
it should meet the correct objective for the given assignment

What I have tried:

dict2 = dict1.inverse()
dict2 = dict1.reverse()
for (key in dict1) {dict2[dict1[key]]=key}
Posted
Updated 18-Jan-23 23:53pm

1 solution

Simple:
JavaScript
const Dict1 = { "one": 1, "two": 2, "three": 3 };
const Dict2 = {};

for (const [key, value] of Object.entries(Dict1)) {
	Dict2[value] = key;
}
Object.entries() - JavaScript | MDN[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900