Skip to content

Instantly share code, notes, and snippets.

@wejrowski
Last active September 15, 2015 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wejrowski/8c42a4c9b6cb89f6a7b1 to your computer and use it in GitHub Desktop.
Save wejrowski/8c42a4c9b6cb89f6a7b1 to your computer and use it in GitHub Desktop.
JS select comparisons
var params = { t: 123, type: 'mytype', channelId: 'mychan', badge:'thebadge' };
var allowedPersonParams = ["type", "channelId", "badge", "since", "until"];
// ES5
var result = {};
allowedPersonParams.forEach(function (paramName) {
if (currentParams[paramName]) {
result[paramName] = currentParams[paramName];
}
});
// ES6
// This actually is not what I want since this will place undefined in the object.
var { typechannelId, badge, since, until } = params;
var result = { typechannelId, badge, since, until };
// Lodash
var result = _.pick(params, allowedPersonParams);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment