There is a two match according to the URL I submit. They are 'en-gb' and 'uk-ireland'
URL: https://www.myabcalphabeta.com/en-gb/destinations/uk-ireland
But when I return the function it is returning only the last one, which is 'uk-ireland'
How do I catch the first match "en-gb". I also see the the loop is working fine since it is returning both value.
Screenshot of output in console.
$(document).ready(function(){
function getURLLocale() {
var url = $(location).attr("href");
var localeRegex = /^[a-z][a-z]-[a-z][a-z]/g;
var urlBreakdown = url.split("/");
console.log(urlBreakdown);
var lang = "en";
var country = "gb";
for(var i = 0; i < urlBreakdown.length; i++) {
if(urlBreakdown[i].match(localeRegex)) {
lang = urlBreakdown[i].split("-")[0];
country = urlBreakdown[i].split("-")[1];
console.log(lang+ "\n");
};
}
return([lang, country]);
} // End function getURLLocale()
console.log(getURLLocale());
})