Remove duplicated items in array

+1 Steven the awesome · March 4, 2015
So I have some jQuery code and I have to delete all the duplicated items in the table when I click on submit. Anyone know how to do this 





$(document).ready(function() {
document.getElementById('button').onclick = function() {
var array = $.makeArray(document.getElementsByClassName('leeftijd'));
$(array).appendTo(document.body);
};
});





Post a Reply

Replies

Oldest  Newest  Rating
0 Mathias Frits Rørvik · March 4, 2015
create a set from the array. =)

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
0 Steven the awesome · March 4, 2015
Here the html code, sorry for ot using the code tags, but the code tags messed up the html code.

<table border="1px">
<tr>
<th>Naam</th>
<th>Woonplaats</th>
<th>Leeftijd</th>
</tr>
<tr>
<td></td>
<td>Vlaardingen</td>
<td class="leeftijd">21</td>
</tr>
<tr>
<td></td>
<td>Vlaardingen</td>
<td class="leeftijd">13</td>
</tr>
<tr>
<td></td>
<td>Vlaardingen</td>
<td class="leeftijd">44</td>
</tr>
<tr>
<td></td>
<td>Vlaadingen</td>
<td class="leeftijd">47</td>
</tr>
<tr>
<td></td>
<td>Limburg</td>
<td class="leeftijd">45</td>
</tr>
<tr>
<td></td>
<td>Limburg</td>
<td class="leeftijd">12</td>
</tr>
<tr>
<td></td>
<td>Limburg</td>
<td class="leeftijd">10</td>
</tr>
<tr>
<td></td>
<td>Rotterdam</td>
<td class="leeftijd">21</td>
</tr>
<tr>
<td></td>
<td>Vlaardingen</td>
<td class="leeftijd">79</td>
</tr>
<tr>
<td></td>
<td>Vlaardingen</td>
<td class="leeftijd">75</td>
</tr>
<table><br>

<input type="submit" value="enter" id="button">
0 Steven the awesome · March 4, 2015
But it should delete all the duplicated items automaticly.
0 Mathias Frits Rørvik · March 4, 2015
A set does not allow duplicated items.
0 Steven the awesome · March 4, 2015
Ooo oke
0 Mathias Frits Rørvik · March 4, 2015
Better go read up on data structures, dude! :P
  • 1

Javascript

107,269 followers
About

A scripting language that is added to standard HTML to create interactive effects, apps, games for the browser.

Links
Moderators