Skip to content
Mithril.js 2
Main Navigation GuideAPI

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

English

简体中文
繁體中文
Español
Français
Русский
Português – Brasil
Deutsch
日本語
한국어
Italiano
Polski
Türkçe
čeština
magyar

Appearance

Sidebar Navigation

API

Core API

m

m.render

m.mount

m.route

m.request

m.parseQueryString

m.buildQueryString

m.buildPathname

m.parsePathname

m.trust

m.fragment

m.redraw

m.censor

Optional API

Stream

Guide

On this page

parseQueryString(string) ​

Description ​

Turns a string of the form ?a=1&b=2 to an object

javascript
var object = m.parseQueryString('a=1&b=2');
// {a: "1", b: "2"}

Signature ​

object = m.parseQueryString(string)

ArgumentTypeRequiredDescription
stringStringYesA querystring
returnsObjectA key-value map

How to read signatures

How it works ​

The m.parseQueryString method creates an object from a querystring. It is useful for handling data from URL

javascript
var data = m.parseQueryString('a=hello&b=world');

// data is {a: "hello", b: "world"}

Boolean type casting ​

This method attempts to cast boolean values if possible. This helps prevents bugs related to loose truthiness and unintended type casts.

javascript
var data = m.parseQueryString('a=true&b=false');

// data is {a: true, b: false}

Leading question mark tolerance ​

For convenience, the m.parseQueryString method ignores a leading question mark, if present:

javascript
var data = m.parseQueryString('?a=hello&b=world');

// data is {a: "hello", b: "world"}

Deep data structures ​

Querystrings that contain bracket notation are correctly parsed into deep data structures

javascript
m.parseQueryString('a[0]=hello&a[1]=world');

// data is {a: ["hello", "world"]}
Pager
Previous pagem.request
Next pagem.buildQueryString

Released under the MIT License.

Copyright (c) 2024 Mithril Contributors

https://mithril.js.org/parseQueryString.html

Released under the MIT License.

Copyright (c) 2024 Mithril Contributors