Created
September 10, 2018 03:33
-
-
Save monsterooo/d61e5974acbb41581b2536a73a7bdd70 to your computer and use it in GitHub Desktop.
pick对象key/value
This file contains hidden or 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
const pick = (obj, keys) => { | |
return keys.filter(key => obj.hasOwnProperty(key)).reduce((preValue, key) => { | |
preValue[key] = obj[key]; | |
return preValue; | |
}, {}); | |
}; | |
// var o = { | |
// a: 1, | |
// b: 2, | |
// c: 3 | |
// }; | |
// const result = pick(o, ["a", "c"]); | |
// console.log("测试pick > ", o, result); | |
// 测试pick > {a: 1, b: 2, c: 3} > {a: 1, c: 3} | |
export default pick; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment