I have an array like var arr = [5, 5, 5, 2, 2, 2, 2, 2, 9, 4, 5, 5, 5]; I really want the output to be [5,2,9,4,5]. My logic for this was:
var arr = [5, 5, 5, 2, 2, 2, 2, 2, 9, 4, 5, 5, 5];
[5,2,9,4,5]
Try this:
var a = [5, 5, 5, 2, 2, 2, 2, 2, 9, 4, 5, 5, 5]; uniqueArray = a.filter(function(item, pos) { return a.indexOf(item) == pos; });
See Remove Duplicates from JavaScript Array