mrrsb mrrsb - 10 months ago 57
jQuery Question

Split string with brace to become parameter

If I have a input value "a[123],b[456],c[789]" and I want to return as "a=123&b=456&c789"

I've tried below code but no luck.. Is there a correct way to implement this?

var str = "a[123],b[456],c[789]"
var string = (str).split(/\[|,|\]/);



One option is:

var rep = {'[':'=', ']': '', ',': '&'};
var query = str.replace(/\[|,|\]/g, el => rep[el]);