urlSearchParams.sort()


按现有名称就地排列所有的名称-值对。使用[稳定排序算法][]完成排序,因此保留具有相同名称的名称-值对之间的相对顺序。

特别地,该方法可以用来增加缓存命中。

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

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