Last active
September 15, 2015 18:19
-
-
Save wejrowski/8c42a4c9b6cb89f6a7b1 to your computer and use it in GitHub Desktop.
JS select comparisons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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