Compare two tables JQuery
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<hr>
<table id="one">
<tr>
<td>Gemeente Veenendaal</td>
<td>87.236.1.135</td>
</tr>
<tr>
<td>EnablE-U B.V. HRN</td>
<td>93.94.231.13</td>
</tr>
<tr>
<td>Regio Twente</td>
<td>87.249.111.2</td>
</tr>
<tr>
<td>Gemeente Hilversum</td>
<td>62.21.131.180</td>
</tr>
</table>
<hr>
<table id="two">
<tr>
<td>000000</td>
<td>345</td>
</tr>
<tr>
<td>000001</td>
<td>Gemeente Veenendaal</td>
</tr>
<tr>
<td>000002</td>
<td>321</td>
</tr>
</table>
<hr>
<div id="message">
</div>
</div>
JavaScript
$(document).ready(function() {
var table_one = [];
var table_two = [];
$("#one tr").each(function() {
var temp_string = "";
count = 1;
$(this).find("td").each(function() {
if (count == 2) {
temp_string += "/";
}
temp_string = temp_string + $(this).text();
count++;
});
table_one.push(temp_string);
});
$("#two tr").each(function() {
var temp_string = "";
count = 1;
$(this).find("td").each(function() {
if (count == 2) {
temp_string += "/";
temp_string = temp_string + $(this).text();
} else {
temp_string = temp_string + $(this).text();
}
count++;
});
table_two.push(temp_string);
});
console.log(table_one);
console.log(table_two);
var message = "";
for (i = 0; i < table_two.length; i++) {
var flag = 0;
var temp = 0;
table_two_entry = table_two[i].split("/");
table_two_cell_one = table_two_entry[0];
table_two_cell_two = table_two_entry[1];
console.log(table_two_cell_one+":"+table_two_cell_two);
for (j = 0; j < table_one.length; j++) {
table_one_entry = table_one[j].split("/");
table_one_cell_one = table_one_entry[0];
table_one_cell_two = table_one_entry[1];
console.log("1)"+table_one_cell_one+":"+table_one_cell_two);
if (table_two_cell_one == table_one_cell_one) {
flag++;
if (table_one_cell_two == table_two_cell_two) {
flag++;
break;
} else {
temp = table_one_cell_two;
}
} else {}
}
if (flag == 2) {
message += table_two_cell_one + " " + table_two_cell_two + " found in first table<br>";
} else if (flag == 1) {
message += table_two_cell_one + " bad - first table has " + temp + "<br>";
} else if (flag == 0) {
message += table_two_cell_one + " not found in first table<br>";
}
}
$('#message').html(message);
});