Last active
December 25, 2015 03:19
-
-
Save eloone/6908908 to your computer and use it in GitHub Desktop.
Filter an object with another object's properties with UnderscoreJs. Allows to filter unwanted properties out of an object by mapping it on a reference object.
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 book = { | |
title : 'brave new world', | |
author : 'aldous huxley', | |
rating : '2' | |
}; | |
var params = { | |
title : 'lmkwxlkc', | |
author : 'ùsdfdlfmdlf', | |
lkklk : 'lkkklmkkmlk', | |
oppoip :'qlksdoieqsdls' | |
}; | |
*/ | |
var query = _.pick(params, _.keys(book)); | |
/* | |
output : | |
query = { | |
title : 'lmkwxlkc', | |
author : 'ùsdfdlfmdlf' | |
}; | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment