Skip to content

Latest commit

 

History

History
27 lines (19 loc) · 533 Bytes

File metadata and controls

27 lines (19 loc) · 533 Bytes

parseQueryString()

Overview

Parses the query string parameters from a URL and returns them as an object."

Code

A screenshot of the titular code snippet

const parseQueryString = (url) => {
  const queryString = url.split("?")[1];
  const params = {};

  if (queryString) {
    const pairs = queryString.split("&");

    pairs.forEach((pair) => {
      const [key, value] = pair.split("=");
      params[key] = decodeURIComponent(value);
    });
  }

  return params;
};