Created
June 3, 2022 02:08
-
-
Save Octagon-simon/158689dfc42e903dd8bea5db79719164 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
| function doQuery(url, userQuery){ | |
| //construct a new url | |
| let res = new URL(url); | |
| //check if userquery contians properties | |
| if(Object.keys(userQuery).length !== 0){ | |
| //loop through object | |
| let ind = 0; | |
| while (ind < Object.keys(userQuery).length){ | |
| //get the parameter | |
| const param = Object.keys(userQuery)[ind]; | |
| //get the value | |
| const value = userQuery[param]; | |
| //set or replace the parameter | |
| res.searchParams.set(param, value); | |
| //increment counter | |
| ind++; | |
| } | |
| } | |
| //return the full URL | |
| return ( res.href ); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment