I have a Jquery code to loop through a table and select unique values, then populate another table with these unique values. My code is as follows:
var items = [], options = [];
//Iterate all td's in first column
$('#PartsTable tr td:nth-child(1)').each(function () {
//add item to array
items.push($(this).text());
});
//restrict array to unique fleet numbers
var items = $.unique(items);
});
//iterate unique array and build array of select options
// ERROR HERE - 'ITEMS IS UNDEFINED'
$.each(items, function(i, item) {
options.push('<tr><td align="left" valign="top">' + item + '</td><td class="delete" align="center" style="background-color: transparent;"><i class="fa fa-times text-red cur-pon"></i></td></tr>');
});
//finally append the items from the array
$('#OrderSummaryTbody').append(options.join());
However I'm getting an error on the line marked above - 'items is undefined'
When I run the debugger in Chrome, var items = $.unique(items); clearly returns an array with 2 values in it.
Can anyone shed any light on this? Thanks!