Forum Discussion
tstack
9 years agoFormer Employee
Same idea, except you’d want to use the ‘findIndex()’ method with a custom predicate instead of the ‘indexOf()’ method, like so:
$arr.filter((item, pos, a) => a.findIndex(elem => item.ProductNum == elem.ProductNum) == pos)
So, the ‘findIndex()’ method will walk through the array and evaluate the predicate function (elem => item.ProductNum == elem.ProductNum) on every element in the array. If a match is found, the index is returned and, if it’s the same index as the current element being examined in the filter, then we add the element to output list.
Tanmay_Sarkar
6 years agoNew Contributor III
Hello,
Is there a way we can totally remove the duplicates values from the array?
For instance if my array looks like [1,2,3,1,3,4,5], I want them separated out with each other like [2,4,5] and [1,1,3,3]