Convert URL parameters to a JavaScript Object

Given an URL with parameters in it, The task is to get those parameters and convert them to an JavaScript Object using javascript. we’re going to discuss few techniques.
First this property to know.

  • replace() method
    This method searches a string for a defined value, or a regular expression, and returns a new string with the replaced defined value.
    Syntax:

    string.replace(searchVal, newvalue)
    

    Parameters:

    • searchVal: This parameter is required. It specifies the value, or regular expression, that is going to replace by the new value.
    • newvalue: This parameter is required. It specifies the value to replace the search value with.

    Return value:
    Returns a new string where the defines value(s) has been replaced by the new value.

  • split() method
    This method is used to split a string into an array of substrings, and returns the new array.
    Syntax:

    string.split(separator, limit)
    

    Parameters:

    • separator: This parameter is optional. It specifies the character, or the regular expression, to use for splitting the string. If not used, the whole string will be returned (an array with only one item)
    • limit: This parameter is optional. It specifies the integer that specifies the number of splits, items beyond the split limit will be excluded from the array.

    Return value:
    Returns a new Array, having the splitted items.