---
title: "jquery read table"
author: "夜鸣猪"
date: "2013-04-10T20:54:03Z"
tags: []
categories: ["编程语言"]
slug: "jquery-read-table"
draft: false
lastmod: "2013-04-10T20:54:03Z"
id: 1845371
url: "https://hlee.iteye.com/blog/1845371"
---

```js

$('#mytable tr').each(function() {
    var customerId = $(this).find("td").eq(2).html();    
});


var items=[], options=[];

//Iterate all td's in second column
$('#tableId>tbody>tr>td:nth-child(2)').each( function(){
   //add item to array
   items.push( $(this).text() );       
});

//restrict array to unique items
var items = $.unique( items );

//iterate unique array and build array of select options
$.each( items, function(i, item){
    options.push('<option value="' + item + '">' + item + '</option>');
})

//finally empty the select and append the items from the array
$('#selectId').empty().append( options.join() );

```