我需要对从 HTML 表中获取的数据进行统计。 第一列是 gatewayId,第二列是 statusId,第三列是 gsmError。 我成功过滤了该表并将这些值插入数组中。
现在我需要从该数组中创建一个唯一网关的列表。 我不知道该数组中将包含哪些值,我只知道它们包含在“10”列中。
数组看起来像这样: [“2951”、“3”、“511”、“2737”、“3”、“502”、“2737”、“3”、“502”、“2732”...]
let messageLogTable = $("#tableId");
var filteredColData = [];
messageLogTable.find('tr').each(function(rowIndex, rowData) {
if(rowIndex > 0){
$(this).find('td').each(function(colIndex, colData) {
if(colIndex === 10 || colIndex === 11 || colIndex === 17) {
filteredColData.push($.trim(colData.textContent));
}
});
}
});
console.log(filteredColData);
结果应该是这样的: 2951, 2737, 2732
如果可能的话,我希望这是使用 jQuery 完成的。
谢谢!
最佳答案
我将按如下方式完成这项工作;
var data = ["2951", "3", "511", "2737", "3", "502", "2737", "3", "502", "2732"],
gatewayID = [...new Set(data.reduce((p,c,i) => !(i%3) ? p.concat(c) : p, []))]
console.log(gatewayID)
关于javascript - 数组中的唯一值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39662728/