I need to identify exactly some country letters in a browser address field and use them in an IF condition but I'm not sure that the way I'm identifying the letters in the link is correct using .include('dk').
So far, I created a variable:
const findUrl = "http://www.example.com/dk"; //window.location.href
//const result = /\.com\/(\w{2})\//.exec(findUrl);
I use a forEach to loop through an array of objects where I have a lot of IF's which contain the letters found.
groupData.forEach(function (group) {
if(findUrl.includes('dk') && group.data[2].id === 'DK') {
polygonTemplate.tooltipHTML = '<b>{countryDK}</b><strong><p style="color:#a8b621;">{linkNameDK}</p></strong>';
polygonTemplate.events.on("hit", function (ev) {
chart.closeAllPopups();
let popupContent = ev.target.dataItem.dataContext.linkDK.map((url, urlIndex) =>
`${(url.length) ? `<a href="${encodeURI(url)}">${ev.target.dataItem.dataContext.linkNameDK[urlIndex]}</a><br>` : ''} `
).join('');
});
}
How can I write better findUrl.includes('dk') in order to find an exact match of letters in a link?
Aucun commentaire:
Enregistrer un commentaire