Skip to content

Instantly share code, notes, and snippets.

@TrevorS
Created July 29, 2015 20:14
Show Gist options
  • Save TrevorS/82bdc1687ea682336d86 to your computer and use it in GitHub Desktop.
Save TrevorS/82bdc1687ea682336d86 to your computer and use it in GitHub Desktop.
function slice(object, keys) {
return keys.reduce(function(results, key) {
if (object.hasOwnProperty(key)) {
results[key] = object[key];
}
return results;
}, {});
}
var h = { a: 1, b: 2, c: 3 };
var results = slice(h, ['a', 'b']);
console.log(results);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment