[Solved] javascript – Break search query string into object


You may want to take a look at this:

addEventListener('load', function(){

var wtf="arg1:"2 words" business corporate arg2:val2 arg3:"fixedIt"";
function customObj(string){
  var a = string.split(/\s+(?!\w+")/), x = [], o = {};
  for(var i=0,s,k,l=a.length; i<l; i++){
    s = a[i].split(/:/); k = s[0];
    s[1] ? o[k] = s[1].replace(/"/g, '') : x.push(k);
  }
  o['extra'] = x.join(' ');
  return o;
}
console.log(customObj(wtf));

});

5

solved javascript – Break search query string into object