Answer the question
In order to leave comments, you need to log in
How to convert three arrays to url and back?
Hello, there are three arrays, they store information in this form
el_1: "option_1_3", el_2: "option_1_2" //первый массив
el_1: "option_2_2", el_2: "option_2_3" //второй
el_1: "option_3_1", el_2: "option_3_2" // третий
var query = build_query(arr1, 5) +'%' + build_query(arr2, 5) +'%' + build_query(arr3, 5);
//результат
query = el_1=option_1_3&el_2=option_1_2%el_1=option_2_2&el_2=option_2_3%el_1=option_3_1&el_2=option_3_2
Answer the question
In order to leave comments, you need to log in
There is jQuery in the question tags, if you use it, then why do you need http_build_query.js
$ .param() to translate back, you can create your own small method or googleunparam, deparam
;(function($) {
$.extend({
unparam: function(param) {
if (param[0] === '?') param = param.slice(1);
var re = {};
for (var i = 0, arr = param.split('&'), kv; kv = arr[i]; i++) {
kv = kv.split('=');
re[kv[0]] = kv[1];
}
return re;
}
});
})(jQuery);
var param = $.param({
el_1: 'option_1_3',
el_2: 'option_1_2'
});
//> "el_1=option_1_3&el_2=option_1_2"
var decode = $.unparam(param);
//> {el_1: "option_1_3", el_2: "option_1_2"}
In your question, I would recommend using objects.
If I understood correctly, then you need to get the values of each key!?
"and it was possible to parse the link to display the same elements" - Do you mean parse the link?
As an object, it would look like this:
{
el_1 : "option_1_3",
el_2 : "option_1_2",
el_3 : "option_2_2",
el_4 : "option_2_3",
el_5 : "option_3_1",
el_6 : "option_3_2"
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question