0

I am trying to eliminate duplicate elements in a array, the thing is that my array has the following:

var array=[];
array[0]["firstColumn"]="Peter";
array[0]["SecondColumn"]=[];
array[1]["firstColumn"]="Peter";
array[1]["SecondColumn"]=[];

I tried something like this but it will only eliminate the array if in each value it has only a string

$.each($scope.array, function(i, el){
    if($.inArray(el.Adultos, uniqueNames) === -1) uniqueNames.push(el);
});
Craicerjack
  • 6,203
  • 2
  • 31
  • 39
dreid
  • 163
  • 2
  • 17
  • Possible duplicate of [Remove Duplicates from JavaScript Array](http://stackoverflow.com/questions/9229645/remove-duplicates-from-javascript-array) – Craicerjack Nov 09 '16 at 12:31
  • You should search before you ask a question. Chances are there are answers already out there, especially for a question like this. – Craicerjack Nov 09 '16 at 12:32
  • I got it from there, but the array from there is different from my one, the one there is like this var names = ["Mike","Matt","Nancy","Adam","Jenny","Nancy","Carl"]; – dreid Nov 09 '16 at 12:33
  • The array is made of key value – dreid Nov 09 '16 at 12:34
  • Can you provide your array? – Yosvel Quintero Nov 09 '16 at 12:46
  • You array does not work in a javascript emulator to start with. – Alfonso Fernandez-Ocampo Nov 09 '16 at 12:47
  • In the console.log I have: Array [ Array[0], Array[0], Array[0] ] and each one is: Age:Array[0],Adult:"2",Amount:"2" – dreid Nov 09 '16 at 12:51
  • An array of key values is an array of objects and in javascript looks like this `[{"firstColumn": "Peter", "SecondColumn" : [] }, {"firstColumn": "Peter", "SecondColumn" : [] }]` which would make your code look like this `array[0] = {"firstColumn": "Peter", "SecondColumn" : [] }; array[1] = {"firstColumn": "Peter", "SecondColumn" : [] }` – Craicerjack Nov 09 '16 at 14:22
  • 1
    Your console log means your data is an array of arrays and looks like this `[ [{ Age:Array[0], Adult:"2", Amount:"2"}], [{ Age:Array[0], Adult:"2", Amount:"2"}], [{ Age:Array[0], Adult:"2", Amount:"2"}] ] `. Where is your data coming from, can you format it, and whats your end goal? – Craicerjack Nov 09 '16 at 14:27

0 Answers0