I am new to jquery, please i need some help.
I want to eliminate the duplication in arrays, below is my function:
function unique(list) {
var result = [];
$.each(list, function(i, e) {
if ($.inArray(e, result) == -1) { result.push(e); }
else {}
});
return result;
}
It works well with duplicated arrays but when I use it for one without duplicated content it returns a string.
For example if my array is [1, 2, 2, 3, 1] ==> it returns [1, 2, 3]
But when a I have like this array [1, 2] ==> it returns 12
(I need to return an array [1, 2]). I want to known how can I correct it.
Thanks.