I have the following array:
var indexes = {
'spear' : $('#commands_table th:has(img[src*="unit_spear"])').index(),
'sword' : $('#commands_table th:has(img[src*="unit_sword"])').index(),
'axe' : $('#commands_table th:has(img[src*="unit_axe"])').index(),
'archer' : $('#commands_table th:has(img[src*="unit_archer"])').index(),
'spy' : $('#commands_table th:has(img[src*="unit_spy"])').index(),
'light' : $('#commands_table th:has(img[src*="unit_light"])').index(),
'marcher' : $('#commands_table th:has(img[src*="unit_marcher"])').index(),
'heavy' : $('#commands_table th:has(img[src*="unit_heavy"])').index(),
'ram' : $('#commands_table th:has(img[src*="unit_ram"])').index(),
'cata' : $('#commands_table th:has(img[src*="unit_catapult"])').index(),
'noble' : $('#commands_table th:has(img[src*="unit_noble"])').index(),
'knight' : $('#commands_table th:has(img[src*="unit_knight"])').index(),
};
Sometimes it'll find a certain name, sometimes it won't. What I want to do is:
var numberspear = $(this).closest('tr').children().eq(indexes[spear]).text();
Wich obviously won't work for a unit if it doens't exist. Now, i could obviously check every index seperatly, but that's not really efficient... Is there a way to check every value of my array and, if it doens't exist, remove it from the array?
Thanks
indexes['spear']orindexes.spearinstead$("#commands_table th")and usefilter()!!