Last Updated: February 25, 2016
·
406
· Alex Navasardyan

parse url and get parameters using JS

Using regex:

function getUrlParameters(url) { 
    var parameters = {};

    url.replace(/[?&]+([^=&]+)=([^&]*)/gi, function (m, key, value) {
                parameters[key] = value;
    });

    return parameters;
}

alert(getUrlParameters("k=10&i=7"));