Created
June 21, 2019 07:16
-
-
Save srdjanRakic/4c21a7e96d96adb39ed5d138e58364db to your computer and use it in GitHub Desktop.
Filter Object by key
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 metadata = { | |
| 'asset_yolo': 'yolo', | |
| 'preview_img': 'preview_img', | |
| 'asset_test': 'test', | |
| 'image_url': 'url' | |
| } | |
| function filterByKey([key]) { | |
| return key.startsWith('asset_'); | |
| } | |
| function mapMetadataToArray([key, value]) { | |
| return { key: key.replace(/asset_/g, ''), value }; | |
| } | |
| const data = Object.entries(metadata) | |
| .filter(filterByKey) | |
| .map(mapMetadataToArray); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment