In the application, I have a table where I add multiple values to an Array. These arrays display the values in the table columns, sometimes resulting in duplicate values. Below is a small example to illustrate the issue.
What is the best way to eliminate duplicate values in the ColumnValue Arrays?
methods: {
caseFileDetailedTableData(row) {
console.log(row=
return [
{
columnName: I18n.t('ccenter.case_file.table.total_debt_outstanding'),
columnValue: row.totalDebtOutstanding
},
{
columnName: I18n.t('ccenter.case_file.table.company_names'),
columnValue: row.debtorInfo.companyNames.join(', ') || '-'
},
{
columnName: I18n.t('ccenter.case_file.table.aliases'),
columnValue: row.debtorInfo.aliases.join(', ') || '-'
},
{
columnName: I18n.t('ccenter.case_file.table.birthdates'),
columnValue: row.debtorInfo.birthdates.join(', ') || '-'
},
{
columnName: I18n.t('ccenter.case_file.table.phones'),
columnValue: row.debtorInfo.phones.join(', ') || '-'
},
{
columnName: I18n.t('ccenter.case_file.table.emails'),
columnValue: row.debtorInfo.emails.join(', ') || '-'
},
{
columnName: I18n.t('ccenter.case_file.table.addresses'),
columnValue: row.debtorInfo.addresses.join(', ') || '-',
},
{
columnName: I18n.t('ccenter.case_file.table.customer_numbers'),
columnValue: row.debtorInfo.customerNumbers.join(', ') || '-'
},
{
columnName: I18n.t('ccenter.case_file.table.contract_numbers'),
columnValue: row.contractNumbers.join(', ') || '-'
},
{
columnName: I18n.t('ccenter.case_file.table.invoice_numbers'),
columnValue: row.invoiceNumbers.join(', ') || '-'
},
]
}
}
}
Previously Used Methods:
fields.forEach(field => {
if (participant[field.fieldName].length > 0) {
const uniqueValues = [];
const uniqueElements = [];
participant[field.fieldName].forEach(element => {
if (!uniqueValues.includes(element.value)) {
uniqueValues.push(element.value);
uniqueElements.push(element);
}
...
removeDuplicateValues(p){
return Object.keys(p).map(k => Array.isArray(p[k]) ? { [k]: removeDuplicates(p[k]) } : { [k]: p[k] }).reduce((acc, item) => ({...acc, ...item}), {});
},
removeDuplicates(arr){
return [...new Set(arr)];
console.log(arr)
},
EDIT: Example of Repetition Cited:
Date of birth 1982-12-18
Phone numbers 354, 3541914408, 3541914408, 3541914408