Last active
April 13, 2024 21:03
-
-
Save bisubus/2da8af7e801ffd813fab7ac221aa7afc to your computer and use it in GitHub Desktop.
ES5/ES6/ES2017/ES2019 omit & pick
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
|
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
Object.keys(obj) | |
.filter((key) => ['blacklisted', 'keys'].indexOf(key) < 0) | |
.reduce((newObj, key) => Object.assign(newObj, { [key]: obj[key] }), {}) |
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
Object.entries(obj) | |
.filter(([key]) => !['blacklisted', 'keys'].includes(key)) | |
.reduce((obj, [key, val]) => Object.assign(obj, { [key]: val }), {}); |
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
Object.fromEntries( | |
Object.entries(obj) | |
.filter(([key]) => !['blacklisted', 'keys'].includes(key)) | |
); |
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
Object.keys(obj) | |
.filter((key) => ['whitelisted', 'keys'].indexOf(key) >= 0) | |
.reduce((newObj, key) => Object.assign(newObj, { [key]: obj[key] }), {}) |
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
Object.entries(obj) | |
.filter(([key]) => ['whitelisted', 'keys'].includes(key)) | |
.reduce((obj, [key, val]) => Object.assign(obj, { [key]: val }), {}); |
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
Object.fromEntries( | |
Object.entries(obj) | |
.filter(([key]) => ['whitelisted', 'keys'].includes(key)) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another solution to pick