Lodash _.fromQuery() Method

The Lodash _.fromQuery() method is used to convert the given URL Query String into an equivalent JavaScript object.

Syntax:

_.fromQuery( URL_Query);

Parameters: This method accepts a single parameter as mentioned above and described below:

  • URL_Query: This method takes a URL Query String to convert into JavaScript object.

Return Value: This method returns the equivalent JavaScript Object.

Note: This will not work in normal JavaScript because it requires the lodash.js contrib library to be installed. Lodash.js contrib library can be installed using npm install lodash-contrib –save.

Example 1:

Javascript




// Defining lodash contrib variable 
var _ = require('lodash-contrib'); 
  
var s  = _.fromQuery(
    
console.log("The generated JavaScript Object is : ", s);


Output:

The generated JavaScript Object is :
Object {
color: "purple" ,
https://zambiatek.com/path/to/page?name: "ferret"
}

Example 2:

Javascript




// Defining lodash contrib variable 
var _ = require('lodash-contrib'); 
  
var s  = _.fromQuery(
    
console.log("The generated JavaScript Object is : ", s);


Output:

The generated JavaScript Object is :
Object {https://practice.zambiatek.com/courses/?ref: "gfg_header"}

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Check Also
Close
Back to top button