Skip to content

Commit

Permalink
Improve example for URL: searchParams property (#34714)
Browse files Browse the repository at this point in the history
* use string for URL instead of pretending a page exists, use console.log instead of comments

* linting

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* s/let/cont/

Co-authored-by: skyclouds2001 <[email protected]>

* Update index.md

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: skyclouds2001 <[email protected]>
Co-authored-by: Joshua Chen <[email protected]>
  • Loading branch information
4 people authored Jul 13, 2024
1 parent c7e432e commit b4470d4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions files/en-us/web/api/url/searchparams/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ A {{domxref("URLSearchParams")}} object.

## Examples

If the URL of your page is
`https://example.com/?name=Jonathan%20Smith&age=18` you could parse out
the `name` and `age` parameters using:

```js
let params = new URL(document.location).searchParams;
let name = params.get("name"); // is the string "Jonathan Smith".
let age = parseInt(params.get("age")); // is the number 18
const params = new URL("https://example.com/?name=Jonathan%20Smith&age=18")
.searchParams;
const name = params.get("name");
const age = parseInt(params.get("age"));

console.log(`name: ${name}`); // name: Jonathan Smith
console.log(`age: ${age}`); // age: 18
```

## Specifications
Expand Down

0 comments on commit b4470d4

Please sign in to comment.