Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
/**
* Filter object properties.
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* MIT Style license, 2019
*/
const filterProps = (
[p1, p2, p3],
{
[p1]: _p1,
[p2]: _p2,
[p3]: _p3,
...toKeep
}
) => toKeep;
const data = {
password: 'querty',
accessToken: 'secret',
userID: 13,
userName: 'Yrtimd'
};
const dataToLog = filterProps(
['password', 'accessToken'],
data,
);
console.log(dataToLog); // {userID: 13, userName: 'Yrtimd'}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment