These all are the tags which I'm storing into in an array with those who have Type_ as a prefix
My array have multiple type of values but I'm unable to sort them here is the array
{
Type_5000-10000mAh: [10, "5000-10000mAh", "type_5000-10000mah", "Type_5000-10000mAh", 70],
Type_15000-20000mAh: [1, "15000-20000mAh", "type_15000-20000mah", "Type_15000-20000mAh", 76],
Type_USB-C: [4, "20000-30000mAh", "type_20000-30000mah", "Type_20000-30000mAh", 95],
Type_20000-30000mAh: [4, "20000-30000mAh", "type_20000-30000mah", "Type_20000-30000mAh", 95],
Type_Wireless: [3, "Wireless", "type_wireless", "Type_Wireless", 160],
Type_Quick Charger: [1, "Quick Charger", "type_quick-charger", "Type_Quick Charger", 344]
}
and the output I want is like that
{
Type_5000-10000mAh: [10, "5000-10000mAh", "type_5000-10000mah", "Type_5000-10000mAh", 70],
Type_15000-20000mAh: [1, "15000-20000mAh", "type_15000-20000mah", "Type_15000-20000mAh", 76],
Type_20000-30000mAh: [4, "20000-30000mAh", "type_20000-30000mah", "Type_20000-30000mAh", 95],
Type_USB-C: [4, "20000-30000mAh", "type_20000-30000mah", "Type_20000-30000mAh", 95],
Type_Wireless: [3, "Wireless", "type_wireless", "Type_Wireless", 160],
Type_Quick Charger: [1, "Quick Charger", "type_quick-charger", "Type_Quick Charger", 344]
}
and this is the code I'm using to get this array format
var tags_type = {};
var indexI = 0;
$.each(totPro.products, (productsKey, productsValue) => {
$.each(productsValue.tags, (prodKey, prodVal) => {
indexI++;
if(prodVal.toLowerCase().indexOf('type') > -1){
console.log(prodVal);
if(tags_type[prodVal] == undefined){
tags_type[prodVal] = [0, capitalizeFirstLetter(prodVal.slice(5)), prodVal.toLowerCase().replace(/\s+/g, '-').toLowerCase(), prodVal, indexI];
}
tags_type[prodVal][0]++;
}
});
});
console.log(tags_type);