jQuery: create array with all unique values of a table -


is there way can create array using jquery / js contains unique values table, i.e. without duplicates ? also, values interested in in tds class (myclass) + exclude "" , " " non-valid values.

in below example output should [item1,item2,item3] unique , valid values.

example table:

<table id="mytable">     <thead>         <tr>             <th class="myheader">cat 1</th>             <th>vol 1</th>             <th class="myheader">cat 2</th>             <th>vol 2</th>             <th class="myheader">cat 3</th>             <th>vol 3</th>             //...         </tr>     </thead>     <tbody>         <tr>             <td class="myclass">item1</td><td>8</td><td class="myclass">item2</td><td>7</td><td class="myclass">item1</td><td>2</td>         </tr>         <tr>             <td class="myclass">item3</td><td>5</td><td class="myclass">item2</td><td>7</td><td class="myclass">item2</td><td>4</td>         </tr>         <tr>             <td class="myclass">item3</td><td>1</td><td class="myclass">item1</td><td>5</td><td class="myclass">item3</td><td>3</td>         </tr>         //...     </tbody> </table> 

my js far (not covering duplicates):

var result = new array(); $('td').each(function() {     if( ($(this).text() != '') && ($(this).text() != ' ') {         result.push(+($(this).text()));     } }); alert(result); 

many in advance, tim.

try this

var result = new array(); $('td').each(function() {     if( ($(this).text() != '') && ($(this).text() != ' ') {         if(result.indexof($(this).text()) == -1){             result.push(+($(this).text()));         }     } }); alert(result); 

Comments

Popular posts from this blog

c# - Unity IoC Lifetime per HttpRequest for UserStore -

Change the color of an oval at click in Java AWT -

I am trying to solve the error message 'incompatible ranks 0 and 1 in assignment' in a fortran 95 program. -