URLSearchParams.sort() - Web APIs 编辑
The URLSearchParams.sort()
method sorts all key/value pairs contained in this object in place and returns undefined
. The sort order is according to unicode code points of the keys. This method uses a stable sorting algorithm (i.e. the relative order between key/value pairs with equal keys will be preserved).
Note:
This feature is available in Web Workers.Syntax
searchParams.sort();
Parameters
None.
Return value
undefined
.
Examples
// Create a test URLSearchParams object
var searchParams = new URLSearchParams("c=4&a=2&b=3&a=1");
// Sort the key/value pairs
searchParams.sort();
// Display the sorted query string
console.log(searchParams.toString());
The result is:
a=2&a=1&b=3&c=4
Specifications
Specification | Status | Comment |
---|---|---|
URL The definition of 'sort()' in that specification. | Living Standard | Initial definition |
Browser compatibility
BCD tables only load in the browser
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论