Skip to content

Instantly share code, notes, and snippets.

@chy4egg
Last active December 25, 2018 11:27
Show Gist options
  • Save chy4egg/8ce131c34f3794769a16dd43c4bfdc8c to your computer and use it in GitHub Desktop.
Save chy4egg/8ce131c34f3794769a16dd43c4bfdc8c to your computer and use it in GitHub Desktop.
Object => Array (js)
export default function (obj, property, keys = false) {
if(!obj) return [];
if(Array.isArray(obj)) return obj;
if(keys) return Object.keys(obj);
return Object.keys(obj).map((key) => {
let item = Object.assign(obj[key]);
if(property) {
item[property] = key;
}
return item;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment