Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save michelepatrassi/7e922900ea409d966f9a082ddceb5762 to your computer and use it in GitHub Desktop.
Save michelepatrassi/7e922900ea409d966f9a082ddceb5762 to your computer and use it in GitHub Desktop.
Format object to array of objects
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