[JavaScript] How to merge two arrays and remove duplicates?


I want to merge two arrays and delete duplicates after the merge, how can we do that in Javascript?

1 Answer

3 years ago by

You can use Set along with spread operator to merge two arrays without any duplicates.

[...new Set([...num1,...num2])]

Try checking the above solution here: https://onecompiler.com/javascript/3xmw2gpbe

3 years ago by Meera