jquery - explode, match and get value -


this question has answer here:

i have string:

title=hello world&dropdown=on&count=on&hierarchical=on 

and want explode string &, like;

title=hello world dropdown=on count=on hierarchical=on 

i know names title, dropdown, count,hierarchical (but names not fixed, can anything),

now want match names (name means words before equal sign) name know, if match value (words after equal sign), like:

if (name == myname) value

var myname = dropdown; if (dropdown == myname)alert(dropdown.value) 

split string array, put array object, can compare nicely:

var string = "title=hello world&dropdown=on&count=on&hierarchical=on"; var stringarr = string.split("&"); console.log(stringarr);  var newobj = {};  (var = 0; < stringarr.length; i++) {     var parts = stringarr[i].split("=");     newobj[parts[0]] = parts[1]; }  console.log(newobj); 

now, newobj.title equal hello world. hope helps.

oh, , fiddle: http://jsfiddle.net/kxmlp/


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -