Skip to content

Instantly share code, notes, and snippets.

@eloone
Last active December 25, 2015 03:19
Show Gist options
  • Save eloone/6908908 to your computer and use it in GitHub Desktop.
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.
/*
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