GsMalhotra GsMalhotra - 8 months ago 41
AngularJS Question

How to get unique array with only filter in Javascript

I have an array:

var a = [2,3,4,5,5,4]

I want to get unique array out of given array like

b = [2,3,4,5]

I have tried
a.filter(function(d){return b.indexOf(d)>-1})

and I don't want to use for loop
thanx in advance

Answer Source

you can simply do it in java script , with the help of filter second parameter which is for indexing like this

var a = [2,3,4,5,5,4]
a.filter(function(d,i){return a.indexOf(d)==i})