numOne = [1, 2] numTwo = [1, 3, 1] // original let duplicatedValues = […new Set(numOne)].filter(item => numTwo.includes(item)); // [1] // your let firstValues = new Set(numOne); duplicatedValues = numTwo.filter(item => firstValues.has(item)); // [1, 1]
to solve this we need either to create second Set or to use includes instead of has
Set
includes
has
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
to solve this we need either to create second
Set
or to useincludes
instead ofhas