Created
June 12, 2017 02:04
-
-
Save liuzhuan/29e0c9b7839e123e928bae1777844414 to your computer and use it in GitHub Desktop.
Select some keys from a given 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
function filterParams(source, keys) { | |
let result = {}; | |
keys.forEach(item => { | |
result[item] = source[item]; | |
}); | |
return result; | |
} | |
const source = { | |
name: 'Liu Zhuan', | |
age: '32', | |
sex: 'male' | |
} | |
const result = filterParams(source, ['name', 'sex', 'wife.name']); | |
console.log(result); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment