Last active
June 6, 2019 19:43
-
-
Save chrdek/5a2134d8dc36c3393629374e5d31959e to your computer and use it in GitHub Desktop.
Create array of objects with names, values
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Input string format: 'fd=44&ds=32&dks=1314' is converted to output array of objects.. | |
| String.prototype.ToKVPObj= function(){ | |
| return(this+"&").match(/[a-zA-Z]+(=){1}[a-zA-Z0-9]+(&){1}/gi) | |
| .map(c=> {var a=[]; var dObj={}; | |
| a = c.replace("&","").split("="); | |
| dObj[a[0]]=a[1]; | |
| return dObj; | |
| }); | |
| } | |
| //Example: JSON.stringify("fd=44&ds=32&dks=1314".ToKVPObj()); | |
| //Output: "[{"fd":"44"},{"ds":"32"},{"dks":"1314"}]" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment