Created
April 14, 2021 12:40
-
-
Save 0xtlt/a06847880a101ae0d74807463acae144 to your computer and use it in GitHub Desktop.
String to JSON
This file contains 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
"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})); |
This file contains 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
"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