javascript - How to transform string into object by Lodash -
this question has answer here:
- convert url parameters javascript object 16 answers
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
Post a Comment