Lets say we have a dictionary with unique values:
{ a: 1, b: 2 }
and we would like to swap keys and values like:
{ 1: 'a', 2: 'b' }
how to do it with underscore?
In underscore.js
there is method _.invert
console.log(_.invert({ a: 1, b: 2 }))
<script src="//jashkenas.github.io/underscore/underscore-min.js"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With