JavaScript First query string parameter is not parsed using qs npm package jquery get first query string parameter,redux-first-router query

I fail to parse the first query string parameter using the qs npm package. What am I doing wrong?

I execute these commands in my console

import * as qs from './qs'
var addr = "https://www.somesite.se/?title=querystring&action=edit"
var parsed = qs.parse(addr)

After executing these commands parsed has the value:

{ 'https://www.somesite.se/?title': 'querystring',
  action: 'edit' }

This is strange. Why is title not a property on the returned object? I would expect the value of parsed.title to be 'querystring'. but it is not. The value of parsed.title is undefined.

Why?

Answer:1

qs parses query strings. It does not parse URLs. Use a URL parser (new URL(addr).search.substring(1)) to get the query string from the URL first.

qs.parse("title=querystring&action=edit") should give you a correct answer.

Now that I think about it... why even use qs? new URL(addr).searchParams should already give you the params parsed...

Answer:2

I am trying to add some custom color in the material design base templates, module.js var app = angular.module('AppTool', ['ngMaterial', 'ui.router', 'ngCookies', 'ngResource','ngRoute', 'satellizer'...

I am trying to add some custom color in the material design base templates, module.js var app = angular.module('AppTool', ['ngMaterial', 'ui.router', 'ngCookies', 'ngResource','ngRoute', 'satellizer'...

When running the command knex migrate:make table-name The below code is what appears in the newly created file. exports.up = function (knex, Promise) { }) } exports.down = function (knex, Promise)...

When running the command knex migrate:make table-name The below code is what appears in the newly created file. exports.up = function (knex, Promise) { }) } exports.down = function (knex, Promise)...

Background I want to dynamically put some javascript code in a DIV element using innerHTML. For this, I create a DIV object on my page and two buttons. First button, when pressed should insert some ...

Background I want to dynamically put some javascript code in a DIV element using innerHTML. For this, I create a DIV object on my page and two buttons. First button, when pressed should insert some ...

First note that mod(3^146,293)=292. For some reason, inputting mod(3^146,293) in Matlab returns 275. Inputting Math.pow(3,146) % 293 in JS returns 275. This same error occurs (as far as I can tell) ...

First note that mod(3^146,293)=292. For some reason, inputting mod(3^146,293) in Matlab returns 275. Inputting Math.pow(3,146) % 293 in JS returns 275. This same error occurs (as far as I can tell) ...