Jeanbf
Jeanbf

Reputation: 317

How don't duplicate arrays using each jquery?

Hi I have this code in javascript :

actFinal: function(fecha,datos,rut,nombre){


    var self = this;
    var aFinalDos = new Array();

        $.each(datos, function(index,value){ 
            var date = value.start.substring(0,10);
            $.each(self.aControlesEditados, function(index2,value2){
                var aFinal = new Array();
                var date2 = value2.fecha.substring(0,10);
               if(date2 == date){
                    aFinal.push(value.start,value.estado)
                    aFinalDos.push(aFinal)
               }
            });

        });

        console.info(aFinalDos);

},

And the code print this :

enter image description here

(arrays could be more , but in this case are 6 , and I need show 3)

I need remove the duplicates, I mean ,I only need this :

enter image description here

How can I fix this? sorry my english.

Upvotes: 0

Views: 43

Answers (1)

R-J
R-J

Reputation: 936

UnderscoreJS has an array function called unique, which produces a duplicate-free array.

Only thing - I'm not sure if it will work in this case - because you have array of arrays.

Take a look here: http://underscorejs.org/#uniq

Upvotes: 2

Related Questions