Created
March 16, 2021 19:32
-
-
Save michelepatrassi/7e922900ea409d966f9a082ddceb5762 to your computer and use it in GitHub Desktop.
Format object to array of objects
This file contains 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 tags = { | |
Advertising: "Advertising", | |
Architecture: "Architecture", | |
Aviation: "Aviation", | |
Banking: "Banking", | |
Business: "Business", | |
Construction: "Construction", | |
Design: "Design", | |
Economics: "Economics", | |
Engineering: "Engineering", | |
Entrepreneurship: "Entrepreneurship", | |
Healthcare: "Healthcare", | |
"Higher Education": "Higher Education", | |
Management: "Management", | |
Marketing: "Marketing", | |
Online: "Online", | |
"Personal Finance": "Personal Finance" | |
}; | |
const map = Object.entries(tags) | |
.map(([key, value]) => ({ | |
value: key.toLowerCase().replace(/ /g, "-"), | |
label: value, | |
})) | |
.sort((a, b) => a.label.localeCompare(b.label)); | |
console.log(map); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment