Created
September 9, 2020 14:51
-
-
Save ashwinkumar2438/ccb591e7220d900ab608c38d725de5b2 to your computer and use it in GitHub Desktop.
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
var url="www.go.myurlexample.com/007w3?id1=123&id2=abc"; | |
var getLastString=(param)=>(string)=>string.split(param).slice(-1).join(); | |
var split=(param)=>(string)=>string.split(param); | |
var getParamObj=(arr)=>arr.reduce((acc,str)=>{ | |
var arr=split("=")(str); | |
acc[arr[0]]=arr[1]; | |
return acc;} | |
,{}) | |
var getUrlParams=compose(getParamObj,split("&"),getLastString("?")); | |
getUrlParams(url); //{id1: "123", id2: "abc"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment