Skip to content

Instantly share code, notes, and snippets.

@srdjanRakic
Created June 21, 2019 07:16
Show Gist options
  • Select an option

  • Save srdjanRakic/4c21a7e96d96adb39ed5d138e58364db to your computer and use it in GitHub Desktop.

Select an option

Save srdjanRakic/4c21a7e96d96adb39ed5d138e58364db to your computer and use it in GitHub Desktop.
Filter Object by key
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