Skip to content

Instantly share code, notes, and snippets.

@0xtlt
Created April 14, 2021 12:40
Show Gist options
  • Save 0xtlt/a06847880a101ae0d74807463acae144 to your computer and use it in GitHub Desktop.
Save 0xtlt/a06847880a101ae0d74807463acae144 to your computer and use it in GitHub Desktop.
String to JSON
"str1=hello,str2=world".split(",")
.map(str => str.split("="))
.map(arr => {let tmp = {};tmp[arr[0]]=arr[1];return tmp;})
.reduce((a,b) => ({...a, ...b}));
"str1=hello,str2=world".split(",")
.map((str: string) => str.split("="))
.map((arr: string[]) => {let tmp: {[key: string]: string} = {};tmp[arr[0]]=arr[1];return tmp;})
.reduce((a: {[key: string]: string}, b: {[key: string]: string}) => ({...a, ...b}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment