Last active
December 25, 2018 11:27
-
-
Save chy4egg/8ce131c34f3794769a16dd43c4bfdc8c to your computer and use it in GitHub Desktop.
Object => Array (js)
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
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