Skip to content

Instantly share code, notes, and snippets.

@ahmeti
Forked from TravelingTechGuy/Object2QS.js
Created April 13, 2018 16:40
Show Gist options
  • Save ahmeti/7a0681c92817bc9ac9d8ff630382e70d to your computer and use it in GitHub Desktop.
Save ahmeti/7a0681c92817bc9ac9d8ff630382e70d to your computer and use it in GitHub Desktop.
JSON object to query string (using underscore/lodash)
var objectToQueryString = function(obj) {
var qs = _.reduce(obj, function(result, value, key) {
return (!_.isNull(value) && !_.isUndefined(value)) ? (result += key + '=' + value + '&') : result;
}, '').slice(0, -1);
return qs;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment