I have 3 objects which contain information about svg icons (FontAwesome). Every object has the same structure but the prefix property has a different value. The object below uses fab as the prefix, the second far and the third fas.
{
"facebook": {
"prefix": "fab",
"iconName": "facebook-alt",
"icon": [
448,
512,
[],
"f26e",
"M103.3 344.3c-6.5-14.2-6.9-18.3 7.4-23.1 25.6-8 8 9.2 43.2 49.2h.3v-93.9c1.2-50.2 44-92.2 97.7-92.2 53.9 0 97.7 43.5 97.7 96.8 0 63.4-60.8 113.2-128.5 93.3-10.5-4.2-2.1-31.7"
]
},
"twitter": {
"prefix": "fab",
"iconName": "twitter",
"icon": [
448,
512,
[],
"f368",
"M423.9 255.8L411 413.1c-3.3 40.7-63.9 35.1-60.6-4.9l10-122.5-41.1 2.3c10.1 20.7 15.8 43.9 15.8 68.5 0 41.2-16.1 78.7-42.3 106.5l-39.3-39.3c57.9-63.7 13.1-167.2-74-167.2-25.9 0-49.5"
]
},
"instagram": {
"prefix": "fab",
"iconName": "instagram",
"icon": [
640,
512,
[],
"f369",
"M482.2 372.1C476.5 365.2 250 75 242.3 65.5c-13.7-17.2 0-16.8 19.2-16.9 9.7-.1 106.3-.6 116.5-.6 24.1-.1 28.7.6 38.4 12.8 2.1 2.7 205.1 245.8 207.2 248.3 5.5 6.7 15.2 19.1 7.2"
]
},
}
Second object:
{
"arrowUp": {
"prefix": "far",
"iconName": "arrow-up",
"icon": [
448,
512,
[],
"f26e",
"M103.3 344.3c-6.5-14.2-6.9-18.3 7.4-23.1 25.6-8 8 9.2 43.2 49.2h.3v-93.9c1.2-50.2 44-92.2 97.7-92.2 53.9 0 97.7 43.5 97.7 96.8 0 63.4-60.8 113.2-128.5 93.3-10.5-4.2-2.1-31.7"
]
},
"arrowLeft": {
"prefix": "far",
"iconName": "arrow-left",
"icon": [
448,
512,
[],
"f368",
"M423.9 255.8L411 413.1c-3.3 40.7-63.9 35.1-60.6-4.9l10-122.5-41.1 2.3c10.1 20.7 15.8 43.9 15.8 68.5 0 41.2-16.1 78.7-42.3 106.5l-39.3-39.3c57.9-63.7 13.1-167.2-74-167.2-25.9 0-49.5"
]
},
"arrowRight": {
"prefix": "far",
"iconName": "arrow-right",
"icon": [
640,
512,
[],
"f369",
"M482.2 372.1C476.5 365.2 250 75 242.3 65.5c-13.7-17.2 0-16.8 19.2-16.9 9.7-.1 106.3-.6 116.5-.6 24.1-.1 28.7.6 38.4 12.8 2.1 2.7 205.1 245.8 207.2 248.3 5.5 6.7 15.2 19.1 7.2"
]
},
}
Third object:
{
"carrot": {
"prefix": "fas",
"iconName": "carrot",
"icon": [
448,
512,
[],
"f26e",
"M103.3 344.3c-6.5-14.2-6.9-18.3 7.4-23.1 25.6-8 8 9.2 43.2 49.2h.3v-93.9c1.2-50.2 44-92.2 97.7-92.2 53.9 0 97.7 43.5 97.7 96.8 0 63.4-60.8 113.2-128.5 93.3-10.5-4.2-2.1-31.7"
]
},
"cat": {
"prefix": "fas",
"iconName": "cat",
"icon": [
448,
512,
[],
"f368",
"M423.9 255.8L411 413.1c-3.3 40.7-63.9 35.1-60.6-4.9l10-122.5-41.1 2.3c10.1 20.7 15.8 43.9 15.8 68.5 0 41.2-16.1 78.7-42.3 106.5l-39.3-39.3c57.9-63.7 13.1-167.2-74-167.2-25.9 0-49.5"
]
},
"dog": {
"prefix": "fas",
"iconName": "dog",
"icon": [
640,
512,
[],
"f369",
"M482.2 372.1C476.5 365.2 250 75 242.3 65.5c-13.7-17.2 0-16.8 19.2-16.9 9.7-.1 106.3-.6 116.5-.6 24.1-.1 28.7.6 38.4 12.8 2.1 2.7 205.1 245.8 207.2 248.3 5.5 6.7 15.2 19.1 7.2"
]
},
}
I am trying to turn the 3 objects seen above into this:
"brands": [
"facebook",
"twitter",
"instagram",
],
"regular": [
"arrow-up",
"arrow-left",
"arrow-right",
],
"solid": [
"carrot",
"cat",
"dog",
],
The tricky part is also changing the prefix name into another value for the array. fab would be brands, far regular, and fas solid.
I am using React and have Babel. Here's what I have so far...
const objects = [
...Object.values( fab ),
...Object.values( far ),
...Object.values( fas ),
]
It turns all the objects into arrays but I'm not sure how to get the structure i want.
And for changing the prefix into a name I believe this is a good start... This is just an example for changing fab into brands
//find the index of object from array
const objIndex = objects.findIndex(obj => obj.value === 'fab');
// make new object of updated object
const updatedObj = { ...objects[objIndex], prefix: 'brands'};
// make new array of objects
const updatedObjects = [
...objects.slice(0, objIndex),
updatedObj,
...objects.slice(objIndex + 1),
];