urlSearchParams.sort()


按名称就地对所有现有的名称-值对进行排序。排序是用 稳定排序算法 进行的,因此具有相同名称的名称-值对之间的相对顺序会被保留。

【Sort all existing name-value pairs in-place by their names. Sorting is done with a stable sorting algorithm, so relative order between name-value pairs with the same name is preserved.】

该方法尤其可用于增加缓存命中。

【This method can be used, in particular, to increase cache hits.】

const params = new URLSearchParams('query[]=abc&type=search&query[]=123');
params.sort();
console.log(params.toString());
// Prints query%5B%5D=abc&query%5B%5D=123&type=search