I'm trying to figure out the best way to take an element, compare it to elements in an existing array and if that returns true, push that element into another array with the same index.
I currently have an array but it needs to appear in a certain order so what I've done is created an array with the order it needs to be in. I thought about creating an object where each value of the key is an array and push the elements into the array with is equal to the key but not sure if that's the best way to go about it.
This is the code I am currently working with :
let categories = [];
const categoryOrder = [
"Headings",
"Text",
"Lists & Menus",
"Quotes",
"Banners",
"Images",
"Videos",
"Galleries",
"Logos",
"Clickthrough Images",
"Buttons & CTAs",
"Lines & Dividers",
"Actions",
"Social Media & Integrations",
"Blog, Events & Podcast",
"Ecommerce",
"Navigation",
"Footers",
"Premium",
"Misc",
];
defaultComponents &&
defaultComponents.forEach((component) => {
categories.push(component.category);
});
categories = [...new Set(categories)];
Hope this makes sense.