Skip to content

Instantly share code, notes, and snippets.

@ncoden
Created May 12, 2017 09:51
Show Gist options
  • Save ncoden/1a5220774c5a5d07cbb6bce0bf67b8db to your computer and use it in GitHub Desktop.
Save ncoden/1a5220774c5a5d07cbb6bce0bf67b8db to your computer and use it in GitHub Desktop.
// Filter an object by its keys
exports.objectFilter = function(obj, keys) {
var newObj = {};
var newKeys = Object.keys(obj).filter( (key) => { console.log(keys.indexOf(key)); return keys.indexOf(key) !== -1; });
newKeys.forEach((key) => { newObj[key] = obj[key] });
return newObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment