I have this function which get me only unique values in array:

function sort_unique(arr) {
    var obj = {};
    for (var i = 0; i < arr.length; i++) {
        obj[arr[i]] = true;
    }
    arr = [];
    for (var key in obj) {
        arr.push(key);
    }
    return arr;
}

I need this function to show me repeatedly all uniques in array. Now when I use this in 'for' cycle with index and when all unique values is passed the function return 'undefined'.
Example:
Cat 1 Cat 2 undefined undefined undefined
I need to return:
Cat 1 Cat 2 Cat 1 Cat 2 Cat 1.... etc..

Can you re-work this for me ?
Thanks!

Look at this jsfiddle: https://jsfiddle.net/hebrxo9j/
I get 'undefined', this need to be repeat of 2,66,2,66,2,66 without 'undefined'.
That is what I need.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.