const productConfig = [
{
"id": 1,
"Country": "Brazil",
"Tier": "",
"IBX": "RJ1",
"PriceList": "BR - Price List",
"PriceListDescription": "BR - Price List",
"UOM": "Each",
"Currency": "BRL",
"LastPrice": 0.00,
"AdjustmentType": "Price Override",
"AdjustmentAmount": 4458.29,
"EffectiveStartDate": "0000-00-00",
"EffectiveEndDate": "0000-00-00",
"Product": "Workstation Seat",
"PartNumber": "BC00002.ELEM",
"Attribute_1": "BCTR Room Type",
"Attr_Val_1": "BCTR-DEDICATED",
"Operator_1": "",
"Attribute_2": "Workstation Seat Type",
"Attr_Val_2": "Back Office",
"Operator_2": "",
"Attribute_3": "",
"Attr_Val_3": "",
"Operator_3": "",
"Attribute_4": "",
"Attr_Val_4": "",
"Operator_4": "",
"Attribute_5": "",
"Attr_Val_5": "",
"Operator_5": "",
"Attribute_6": "",
"Attr_Val_6": "",
"Operator_6": "",
"DeleteRule": "",
"Resale": "",
"AccountCategory": ""
},
{
"id": 2,
"Country": "Brazil",
"Tier": "",
"IBX": "RJ1",
"PriceList": "BR - Price List",
"PriceListDescription": "BR - Price List",
"UOM": "Each",
"Currency": "BRL",
"LastPrice": 0.00,
"AdjustmentType": "Price Override",
"AdjustmentAmount": 2229.14,
"EffectiveStartDate": "0000-00-00",
"EffectiveEndDate": "0000-00-00",
"Product": "Workstation Seat - Installation Fee",
"PartNumber": "BC00002.NR",
"Attribute_1": "BCTR Room Type",
"Attr_Val_1": "BCTR-DEDICATED",
"Operator_1": "",
"Attribute_2": "Workstation Seat Type",
"Attr_Val_2": "Back Office",
"Operator_2": "",
"Attribute_3": "",
"Attr_Val_3": "",
"Operator_3": "",
"Attribute_4": "",
"Attr_Val_4": "",
"Operator_4": "",
"Attribute_5": "",
"Attr_Val_5": "",
"Operator_5": "",
"Attribute_6": "",
"Attr_Val_6": "",
"Operator_6": "",
"DeleteRule": "",
"Resale": "",
"AccountCategory": ""
},
{
"id": 3,
"Country": "Brazil",
"Tier": "",
"IBX": "RJ2",
"PriceList": "BR - Price List",
"PriceListDescription": "BR - Price List",
"UOM": "Each",
"Currency": "BRL",
"LastPrice": 0.00,
"AdjustmentType": "Price Override",
"AdjustmentAmount": 4293.60,
"EffectiveStartDate": "0000-00-00",
"EffectiveEndDate": "0000-00-00",
"Product": "Workstation Seat",
"PartNumber": "BC00002.ELEM",
"Attribute_1": "BCTR Room Type",
"Attr_Val_1": "BCTR-DEDICATED",
"Operator_1": "",
"Attribute_2": "Workstation Seat Type",
"Attr_Val_2": "Back Office",
"Operator_2": "",
"Attribute_3": "",
"Attr_Val_3": "",
"Operator_3": "",
"Attribute_4": "",
"Attr_Val_4": "",
"Operator_4": "",
"Attribute_5": "",
"Attr_Val_5": "",
"Operator_5": "",
"Attribute_6": "",
"Attr_Val_6": "",
"Operator_6": "",
"DeleteRule": "",
"Resale": "",
"AccountCategory": ""
},
{
"id": 4,
"Country": "Brazil",
"Tier": "",
"IBX": "RJ2",
"PriceList": "BR - Price List",
"PriceListDescription": "BR - Price List",
"UOM": "Each",
"Currency": "BRL",
"LastPrice": 0.00,
"AdjustmentType": "Price Override",
"AdjustmentAmount": 2146.80,
"EffectiveStartDate": "0000-00-00",
"EffectiveEndDate": "0000-00-00",
"Product": "Workstation Seat - Installation Fee",
"PartNumber": "BC00002.NR",
"Attribute_1": "BCTR Room Type",
"Attr_Val_1": "BCTR-DEDICATED",
"Operator_1": "",
"Attribute_2": "Workstation Seat Type",
"Attr_Val_2": "Back Office",
"Operator_2": "",
"Attribute_3": "",
"Attr_Val_3": "",
"Operator_3": "",
"Attribute_4": "",
"Attr_Val_4": "",
"Operator_4": "",
"Attribute_5": "",
"Attr_Val_5": "",
"Operator_5": "",
"Attribute_6": "",
"Attr_Val_6": "",
"Operator_6": "",
"DeleteRule": "",
"Resale": "",
"AccountCategory": ""
},
{
"id": 5,
"Country": "Brazil",
"Tier": "",
"IBX": "SP1",
"PriceList": "BR - Price List",
"PriceListDescription": "BR - Price List",
"UOM": "Each",
"Currency": "BRL",
"LastPrice": 0.00,
"AdjustmentType": "Price Override",
"AdjustmentAmount": 4376.16,
"EffectiveStartDate": "0000-00-00",
"EffectiveEndDate": "0000-00-00",
"Product": "Workstation Seat",
"PartNumber": "BC00002.ELEM",
"Attribute_1": "BCTR Room Type",
"Attr_Val_1": "BCTR-DEDICATED",
"Operator_1": "",
"Attribute_2": "Workstation Seat Type",
"Attr_Val_2": "Back Office",
"Operator_2": "",
"Attribute_3": "",
"Attr_Val_3": "",
"Operator_3": "",
"Attribute_4": "",
"Attr_Val_4": "",
"Operator_4": "",
"Attribute_5": "",
"Attr_Val_5": "",
"Operator_5": "",
"Attribute_6": "",
"Attr_Val_6": "",
"Operator_6": "",
"DeleteRule": "",
"Resale": "",
"AccountCategory": ""
},
{
"id": 6,
"Country": "Brazil",
"Tier": "",
"IBX": "SP1",
"PriceList": "BR - Price List",
"PriceListDescription": "BR - Price List",
"UOM": "Each",
"Currency": "BRL",
"LastPrice": 0.00,
"AdjustmentType": "Price Override",
"AdjustmentAmount": 2188.08,
"EffectiveStartDate": "0000-00-00",
"EffectiveEndDate": "0000-00-00",
"Product": "Workstation Seat - Installation Fee",
"PartNumber": "BC00002.NR",
"Attribute_1": "BCTR Room Type",
"Attr_Val_1": "BCTR-DEDICATED",
"Operator_1": "",
"Attribute_2": "Workstation Seat Type",
"Attr_Val_2": "Back Office",
"Operator_2": "",
"Attribute_3": "",
"Attr_Val_3": "",
"Operator_3": "",
"Attribute_4": "",
"Attr_Val_4": "",
"Operator_4": "",
"Attribute_5": "",
"Attr_Val_5": "",
"Operator_5": "",
"Attribute_6": "",
"Attr_Val_6": "",
"Operator_6": "",
"DeleteRule": "",
"Resale": "",
"AccountCategory": ""
}];
let deletar = [];
for (let i = 0; i < productConfig.length; i++) {
for (let j in productConfig[i]) {
let x = deletar.indexOf(j);
if(productConfig[i][j] === "" && !~x){
deletar.push(j); // adiciona o nome da chave vazia
}else if(productConfig[i][j] !== "" && ~x){
// remove da array se tiver valor alguma chave vazia que foi adicionada antes
deletar.splice(x,1);
}
}
}
for (let i = 0; i < productConfig.length; i++) {
for(let d of deletar) delete productConfig[i][d];
}
console.log("Colunas deletadas", deletar); // chaves vazias
console.log(productConfig); // json tratado