Typescript – Tips and Tricks Posted by DT-Tech Categories Angular, Uncategorized Date December 23, 2023 Enums to Object Array enum Colors { White, Black, Red, Blue, Green } ————————————————————————————————- ColorsList: any[]; ngAfterViewInit() { this.enumsToObjectList(); } enumsToObjectList() { let keys = Object.keys(Colors); // extract enum key & values let filteredKeys = keys.filter(k => !isNaN(+k)); // filter only non numeric values // compose or transform object array this.ColorsList = filteredKeys.map((k) => { return { key: k, value: Colors[+k] } }); } Share: DT-Tech Previous post Node.js with Express.js - Initial Project Setup December 23, 2023 Next post Angular Styles - Tips and Tricks December 23, 2023