更新时间:2023-02-18 19:23:41
或者......代替:
Alternatively... Instead of:
for (var idx in pairs) {
var pair = pairs[idx].split('=');
if (!!pair[0])
result[pair[0].toLowerCase()] = decodeURIComponent(pair[1] || '');
}
尝试:
result = pairs.reduce(function(a,b) {
var pair = b.split("=");
a[pair[0].toLowerCase()] = decodeURIComponent(pair[1] || '');
return a;
},{});
工作方式相同但使用 reduce()
这是一个原生的javascript函数,可能更快。
Works the same but uses reduce()
which being a native javascript function, is probably faster.