Thursday, March 14, 2019

Filter Unique Value in Array


var items = ['abc','pqr','abc','xyz','pqr','abc'];
var result = items.filter(UniqueElement); 

//result ['abc', 'pqr','xyz']


function UniqueElement(value, index, self) { 
    return self.indexOf(value) === index;
}

No comments:

Post a Comment

Your feedback is always appreciated. I will try to reply to your queries as soon as time allows.Please don't spam,spam comments will be deleted upon reviews.