javascript map replace key value 1

javascript map replace key value

function mapReplace(map){
const x = new Map()
for (const [key, value] of map) {
  x.set(value, key)
}    
return x
}

Here is what the above code is Doing:
1. We create a new Map object called x.
2. We loop through the map object and get the key and value of each item.
3. We set the value as the key and the key as the value in the new Map object.
4. We return the new Map object.

Similar Posts