If the array contains the data shown below:
let array = [{ name: "Ramesh", SalseVersion: 10, MarketingCode: 11 },
{ name: "Suresh", SalseVersion: 12, MarketingCode: 13 },
{ name: "Siva", SalseVersion: 10, MarketingCode: 14 },
{ name: "Sakthi", SalseVersion: 10, MarketingCode: 11 },...]
Then I expect the following result:
[{ name: "Ramesh", SalseVersion: 10, MarketingCode: 11 },
{ name: "Sakthi", SalseVersion: 10, MarketingCode: 11 }]
If the array contains the data shown below:
let array = [{ name: "Ramesh", SalseVersion: 10, MarketingCode: 11 },
{ name: "Suresh", SalseVersion: 12, MarketingCode: 14},
{ name: "Siva", SalseVersion: 12, MarketingCode: 14 },
{ name: "Sakthi", SalseVersion: 10, MarketingCode: 11 },...]
Then I expect the following result:
[{ name: "Ramesh", SalseVersion: 10, MarketingCode: 11 },
{ name: "Sakthi", SalseVersion: 10, MarketingCode: 11 }
{ name: "Suresh", SalseVersion: 12, MarketingCode: 14},
{ name: "Siva", SalseVersion: 12, MarketingCode: 14 }]
I have attempted to solve this by utilizing the following method:
let arr = [{ name: "Ramesh", SalseVersion: 10, MarketingCode: 11 },
{ name: "Suresh", SalseVersion: 12, MarketingCode: 13 },
{ name: "Siva", SalseVersion: 10, MarketingCode: 14 },
{ name: "Sakthi", SalseVersion: 10, MarketingCode: 11 }]
var sorted_arr = arr.slice().sort();
var results = [];
for (var i = 0; i < sorted_arr.length - 1; i++) {
if (sorted_arr[i + 1].SalesVersion == sorted_arr[i].SalesVersion && sorted_arr[i + 1].MarketingCode == sorted_arr[i].MarketingCode) {
results.push(sorted_arr[i]);
}
}
console.log(results);
Unfortunately, I was unable to retrieve the duplicated values. Can you assist me in resolving this issue?
Note: Please note that this solution should work regardless of whether the
SalseVersion
andMarketingCode
values are strings, numbers, or Booleans.
I have tried some of the solutions provided, but I encountered the following error: