javascript - How to transform string into object by Lodash -


this question has answer here:

how transform "t=1&m=6&r=2" {t:1, m:6, r:2} lodash?

you split string , use _.frompairs getting object.

if necessary might use decodeuri decoding string elements %20.

var string = decodeuri("t=1&m=6&r=%20"),      object = _.frompairs(string.split('&').map(s => s.split('=')));        console.log(object);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.15.0/lodash.min.js"></script>


Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -