---
title: "Discussion on \"Get data using current URL with JavaScript\" | Hashnode"
description: "Discussion on \"Get data using current URL with JavaScript\". You can get the URL object using window.location.href like this: \nlet url = new URL(window.location.href)\nThen, parse that URL with split to get the data you need:\nlet id = url.pathname.split('/')[2]\nIn this case, the URL I got was http://127.0.0.1:8..."
url: "https://hashnode.com/posts/get-data-using-current-url-with-javascript/610c57d9528eff11aea86840"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Get data using current URL with JavaScript](https://blog.kellenbaker.com/get-data-using-current-url-with-javascript?utm_source=hashnode&utm_medium=feed)

You can get the URL object using window.location.href like this: let url = new URL(window.location.href) Then, parse that URL with split to get the data you need: let id = url.pathname.split('/')\[2\] In this case, the URL I got was http://127.0.0.1:8...

Aug 5, 2021 · 1 min read · blog.kellenbaker.com  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)

## Written by

[Kellen](https://hashnode.com/@mkb)

@mkb

  
[View profile](https://hashnode.com/@mkb)

Fullstack developer, musician, CI/CD enthusiast

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
