How to get a query string value in JS?

Learn how to get a query string value in JavaScript without jQuery
14 August 2017   2735

You can solve this issue even without jQuery. Here's the code:

function getParameterByName(name, url) {
    if (!url) url = window.location.href;
    name = name.replace(/[\[\]]/g, "\\$&");
    var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
        results = regex.exec(url);
    if (!results) return null;
    if (!results[2]) return '';
    return decodeURIComponent(results[2].replace(/\+/g, " "));
}

Usage:

// query string: ?foo=lorem&bar=&baz
var foo = getParameterByName('foo'); // "lorem"
var bar = getParameterByName('bar'); // "" (present with empty value)
var baz = getParameterByName('baz'); // "" (present with no value)
var qux = getParameterByName('qux'); // null (absent)

Please note: If a parameter is present several times (?foo=lorem&foo=ipsum), you will get the first value (lorem).

Frontend News Digest 5 - 11.10

Three dots in JavaScript, when to use map instead of plain JS object, how to make first React Nattive app and much more
11 October 2019   223

Greetings! I hope your week went great! Here's new Frontend news digest.

One of the greatest things is this digest for newbies is a guid on how to create your first React Native app. Others may learn about the latest NestJS Addons: In-Memory DB update, three dots in JavaScript and interview with "adult" website dev

Guides

  • Clipping, Clipping, and More Clipping! 

Guide on how to use the CSS clip-path property to create interesting effects.

  • Trying to Make Sense of Gmail CSS Support

Highly specialized, but valuable for some specialists guide

  • The tale of three dots in Javascript

Tutorial about the usage of "three consecutive dots" in JS

  • When to Use Map instead of Plain JavaScript Object

Everything should be understandable from the heading, I believe.

  • How to make your first React Native app

You gonna learn how to create a new mobile appl using React Native Starter

Articles

  • ASPIRE: Ideals to Aspire to When Building Websites

Skilled developer made the case that sites should aspire to be Accessible, Secure, Performant, Inclusive, Responsive and Ethical.

  • Interview with Pornhub Team developer

Interesting interview with a guy that works for one of the most popular "adult" websites

  • Verify Phone Numbers On The Web with The SMS Receiver API

Preview of the in-development SMS Receiver API

Updates

  • Node Code Formatter

Automatically formats your code with your preferred code formatter

  • NestJS Addons: In-Memory DB

New version with built-in entity CrUD Controllers, whatever they are