I don't want this duplicates, I can I fix my code?
let caratteristiche = html.match(/<table width="100%">(.*?)<\/table>/mi);
if (caratteristiche) {
for (let el of caratteristiche) {
let element = el.match(/<span class="OD_(red|blue)">(.*?)<\/span><\/td>/mig)
if (element && element.length > 0) {
// <span class="OD_blue">Climatizzazione</span></td>
// <span class="OD_blue">Impianti Gas</span></td>
for (let elem of element) {
try {
let item = elem.match(/<span class="OD_(red|blue)">(.*?)<\/span><\/td>/i);
obj.caratteristiche.push(item[2])
} catch (e) {
//
}
}
} else {
obj.caratteristiche = null
}
}
}
this is my caratteristiche:
Array(2) [<…an="2" class="OD_last_row_red">, <td class="OD_ba…td colspan="2" class="OD_last_row_red">, 1335, <img class="OD_img_omb…an="2" class="OD_last_row_red">, undefined]
and this element that i cycle on it to scrape only text between html tags
Array(6) [Climatizzazione, Impianti Gas, Installazione Ganci traino, Navigatori Autoradio, Pre-revisioni, Consegna a domicilio]
There are several ways of removing duplicates in arrays.
let chars = ['A', 'B', 'A', 'C', 'B'];
let uniqueChars = [...new Set(chars)];
or
let uniqueChars = chars.filter((c, index) => {
return chars.indexOf(c) === index;
});