Split URL String to get each parameter value in the JavaScript

function splitData(){
try {
var value="journreference=123line=A&destination=China&operator=Belbo&departure=104"; 
       // split the string with these characters
        var parts = value.split(/[#\?&]/g); 
        // find the piece with the key "destination"  
         var filteredParts = parts.filter(function (part) {
            return part.split('=')[0] === 'destination';
           });
        // split the value and key, and grab the value [1]
        if (filteredParts) {
            var splitValue = filteredParts[0].split('=')[1];
           }
    }catch (e) {
    log.debug("error split",e)
}
}

Leave a comment

Your email address will not be published. Required fields are marked *