That cool inline evaluation thing is called *Quokka* quokka.devtipsshow.com
@normanperrin64916 жыл бұрын
Instead of creating an `` element, you could use `new URLSearchParams(window.location.search)`. Also in node you could require the `url` lib and use it with `URLSearchParams` or `URL`. If you don't want to split the string yourself you could initialize an `URL` and then access the `url.search` for the search string, or `searchParams` for access the interface of `URLSearchParams`.
@nicoregules6 жыл бұрын
i was about to comment this, using URLSearchParams.entries() you get an iterator with all the key/value pairs
@OfficialDevTips6 жыл бұрын
Thanks for sharing! Great ideas!
@mazyvan6 жыл бұрын
I thought the same
@shgysk8zer06 жыл бұрын
I knew this wouldn't have the real JavaScript solution as soon as I saw `const URL`. Best JavaScript solution: const url = new URL('...'); url.searchParams.delete('gclid'); Done.
@MichaelSalo6 жыл бұрын
Done as long as it's acceptable to crash all versions of IE.
@mazyvan6 жыл бұрын
@@MichaelSalo there's one thing called transpilers
@MichaelSalo6 жыл бұрын
@@mazyvan My understanding is URL object is a browser API not a JS API that would normally be transpiled.
@jameshamann4656 жыл бұрын
You need a polyfill for Internet Explorer
@RomanSteiner_xD6 жыл бұрын
@@MichaelSalo I guess if he uses `URLSearchParams`, he could also use `URL`. Neither work on IE.
@cspear8886 жыл бұрын
Can you also teach how we design our own query parameters?
@mattcroat6 жыл бұрын
You're a treasure David.
@Xizmoify6 жыл бұрын
Not sure if it fits this channel, but perhaps working with node.js and some websockets. Or perhaps building your own npm module
@matthewbarbara29166 жыл бұрын
Each time I needed query params to be allowed in the URL I've always used ?something=value. However, few months ago I needed to convert a JSON object into a query parameter to be passed in the URL and my colleague asked me why would I use such technique to pass the object in the URL rather than having a stringified JSON object pasted in the URL directly. Whilst this sound very ugly to me I could not really provide him an answer more than that most websites pass parameters in the url with ?something=value. What would be the drawback to have example.com/'{"something":"value"}" over the more common practise of ?something=value ?
@OfficialDevTips6 жыл бұрын
You have to escape the characters (so not you happen to have a ”/” that the browser thinks is a path). So a { becomes %7B. Each necessary character in the JSON format takes unnecessary space and you risk of oretty fast rinning into the length limit of urls. See this post blogs.dropbox.com/developers/2015/03/json-in-urls/
@AlvarLagerlof6 жыл бұрын
How about this? You can extract anything after. const url = "test.domain?filter=hardcover&gclid=" const params = new Object() url .split("?")[1] .split("&") .forEach(param => { const [key, value] = param.split("=") params[key] = value }) console.log(params["filter"])
@MightyArts6 жыл бұрын
Hey quick question, what's the name of the VSCode extension that it tells you the value / type etc. of an element or variable when you do //? ? Thanks in advance :D
@OfficialDevTips6 жыл бұрын
It’s called quokka. Link in the description.
@jasonjara34536 жыл бұрын
It's Quokka. quokkajs.com/
@MightyArts6 жыл бұрын
@@OfficialDevTips Thanks a lot for the reply! Love your videos :D
@HashimWarren6 жыл бұрын
why does a.search only produce what's after the ? mark
@HashimWarren6 жыл бұрын
oh, ok - the search method on a string returns everything after the question mark
@mykolasenechyn81776 жыл бұрын
How are getting variable values inline in your code?
@OfficialDevTips6 жыл бұрын
It’s called quokka. Link in the description.
@mykolasenechyn81776 жыл бұрын
@@OfficialDevTips Thanks!
@md.akib51246 жыл бұрын
wow man you are a genius
@pureretro59796 жыл бұрын
Splitting the new URL on the question mark in the 3rd example seemed like a quick solution (although one I'd probably use myself) rather than rebuild the URL from the location.protocol, host and pathname parts. Still, all these options work so it's all good. :-)
@OfficialDevTips6 жыл бұрын
Yeah. Probably it would have been better to show off another way of doing it, the one you suggest is good.
@MrPDTaylor6 жыл бұрын
I just learned this for the first time earlier today! Mere coincidence, I think not!
@zeocamo6 жыл бұрын
Why not just use the new Url() ??? This 3 ways look like walking over the sea to get water
@yassine_klilich6 жыл бұрын
great solution using DOM API (y)
@Dr3amDisturb3r6 жыл бұрын
Eeyyy new intro! Now some sound effects please! :)
@kirillpavlovskii83423 жыл бұрын
Nice
@tekushinio6 жыл бұрын
hej monika XDD
@HeeyStrong6 жыл бұрын
Good to know the good ways of querying those params, thanks lel
@OfficialDevTips6 жыл бұрын
Haha I appreciate someone finds this video useful. Sometimes things you yourself stumble upon are not that interesting to other people. 🙀😅
@SamzehGFX6 жыл бұрын
I created a js micro library for parameter manipulation. Helped me a bunch on some recent projects... github.com/samb97/pram.js
@UniBreakfast5 жыл бұрын
God, the muar from your sweater is painful.)))
@mohamedmorh6 жыл бұрын
keep on hacking :D
@zeocamo6 жыл бұрын
Why not just use the new Url() ??? This 3 ways look like walking over the sea to get water