Remove duplicates from table

Can someone help with the best approach to remove duplicates from the below based on if the Nombre_Completo and last_name has dups.

[

{

“Nombre_Completo”: “Javier”,

“last_name”: “Ruiz”

},

{

“Nombre_Completo”: “Javier”,

“last_name”: “Jose”

},

{

“Nombre_Completo”: “Jose”,

“last_name”: “Tom”

},

{

“Nombre_Completo”: “John”,

“last_name”: “Cruz”

},

{

“Nombre_Completo”: “Javier”,

“last_name”: “Ruiz”

}

]

2 Likes
let result = yourPeopleArray.filter(
    (person, index) => index === yourPeopleArray.findIndex(
      other => person.Nombre_Completo === other.Nombre_Completo
        && person.last_name === other.last_name
    ));
  console.log(result);

hey @javierruiz , this code deletes all the records where NombreCompleto and LastName are duplicates, keeping only the first occurrence

4 Likes

Hi @javierruiz!

The code that @daniele_arcangeli provided is correct! You can use it within an Execute JS code activity.

But you can also use a “lighter” version of the same code directly inside an Assign value to variable activity, by enabling the “Calculate a value” option and using the following value:

people.filter((person, index) => index === people.findIndex(other => person.Nombre_Completo === other.Nombre_Completo && person.last_name === other.last_name))

In this case, people is the variable that contains your array.

If this works, you can mark @daniele_arcangeli’s post or mine as a Solution! Let us know!

3 Likes

Thank you I created JS code but I will also test this lighter code.

1 Like

Thank you this was very useful

1 Like

@Ivan_Ramos quick question on the JS code vs the lighter code in the calculate of value is there a difference in the performance of the Bot runner or just less coding?

Hi @javierruiz!

There is no performance difference between both options. The main difference between both options, aside from the amount of code, is that the Execute JS code activity generates a .js file within the project folder, specifically inside the execute_js_code_scripts subdirectory. The Calculate a value option doesn’t generate those files, as the code resides inside the .neek files themselves.

Hope this answered your question!

1 Like

Thank you for the explanation!