We will be using the JavaScript's built in function split() which splits the string from a separator which is passed as a parameter to this function. The result is stored as an array and we will be using it multiple times since we want to split data into key value pairs, as the server generally processes it.
Just have a look at the following simple code.
URL will be split into parts based on the type of separators you are given in the function.
In this example we gave ('?', '&')
In forEach loop we are checking for the key and value pairs.
Those should be
key1 = firstValue
value1 = name
key2 = secondValue
value2 = email
We are alerting the result that generated here.
For any queries please comment in the bellow comment section.
For more interesting and useful code snippets please follow our blog.