So I have a VueJS table, and sometimes I push double values to this table, I've created the following to remove the doubles before they get pushed onto the table, but I feel I've gone about it wrong, my data does not flow and it's probably too long. Perhaps the filterin should happen right after I declare my Consts? I'd be happy to hear suggestions and examples on how best this can be achieved in my JS.
methods: {
tableDataToDataValueCells(participant) {
const fields = [
{ fieldName: 'companyNames', fieldClass: 'CompanyName' },
{ fieldName: 'aliases', fieldClass: 'Alias' },
{ fieldName: 'addresses', fieldClass: 'Address' },
{ fieldName: 'phones', fieldClass: 'Phone' },
{ fieldName: 'emails', fieldClass: 'Email' },
{ fieldName: 'birthdates', fieldClass: 'Birthdate' },
{ fieldName: 'customerNumbers', fieldClass: 'CustomerNumber' },
{ fieldName: 'ibans', fieldClass: 'BankAccount' },
];
let result = [];
fields.forEach(field => {
if (participant[field.fieldName].length > 0) {
result.push({
attributeName: field.fieldName,
columnName: I18n.t(`ccenter.participant.table.${snakeCase(field.fieldName)}`),
columnValues: participant[field.fieldName],
fieldClass: field.fieldClass,
})
}
});
// return result;
// filter out duplicates here
let array = result;
let unique = [];
data.forEach(element => {
if (!unique.includes(element)) {
unique.push(element)
}
});
return array;
}
}
};