zawhtut
zawhtut

Reputation: 8561

How to get the parent array indside the filter [Flex]?

I have the code as following

var ar:Array = ["Joe","Bob","Curl","Curl"];
var distinctData = ar.filter(function(itm, i){
    return ar.indexOf(itm)== i; 
});

The question is how can I get the parent array ar inside the filter function? I tried this keyword but it wasn't working.

Upvotes: 0

Views: 37

Answers (1)

Marty
Marty

Reputation: 39456

The 2nd argument of filter can be used to provide a value for this within the callback. In your case that means you can do:

ar.filter(function(itm, i) {
    return this.indexOf(itm) === i;
}, ar);

Upvotes: 2

Related Questions