In my grid, I have a dynamically generated array based on filtered values like the example shown below.
[
{
attributeId: 145,
attributeName: "Status",
filterOperator: "Is equal to",
filterValue: "Active",
SortBy: ""
},
{
attributeId: 161,
attributeName: "Code",
filterOperator: "Contains",
filterValue: "22",
SortBy: ""
},
{
attributeId: 161,
attributeName: "Code",
filterOperator: "",
filterValue: "",
SortBy: "ASC"
}
]
In this array, there are two objects with the same 'attributeId', but one contains SortBy details while the other contains filtering details. I want to merge these two objects into one, resulting in:
{
attributeId: 161,
attributeName: "Code",
filterOperator: "Contains",
filterValue: "22",
SortBy: "ASC"
}
If the objects are identical, duplicates can be removed using the following code:
this.columnList = Object.values(this.columnList.reduce((acc, cur) => Object.assign(acc, {
[cur.attributeName]: cur
}), {}));
The 'columnList' is the name of the array. Any suggestions or insights would be greatly appreciated. Thank you!