Skip to content

Instantly share code, notes, and snippets.

@chrdek
Last active June 6, 2019 19:43
Show Gist options
  • Select an option

  • Save chrdek/5a2134d8dc36c3393629374e5d31959e to your computer and use it in GitHub Desktop.

Select an option

Save chrdek/5a2134d8dc36c3393629374e5d31959e to your computer and use it in GitHub Desktop.
Create array of objects with names, values
// 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