-
Notifications
You must be signed in to change notification settings - Fork 22.4k
/
index.md
56 lines (38 loc) · 1 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
---
title: "URLSearchParams: sort() method"
short-title: sort()
slug: Web/API/URLSearchParams/sort
page-type: web-api-instance-method
browser-compat: api.URLSearchParams.sort
---
{{APIRef("URL API")}} {{AvailableInWorkers}}
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).
## Syntax
```js-nolint
sort()
```
### Parameters
None.
### Return value
None ({{jsxref("undefined")}}).
## Examples
```js
// Create a test URLSearchParams object
const 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:
```plain
a=2&a=1&b=3&c=4
```
## Specifications
{{Specifications}}
## Browser compatibility
{{Compat}}