Can I 'match' values in 2 arrays and then use the subsequent 'matched' value? <p>I'm trying to achieve the following though with my intermediate JavaScript skills I'm not sure if this is possible. </p> <p>This is related in part to <a href="http://stackoverflow.com/questions/7992964/how-do-i-display-a-certain-image-based-on-matching-a-value-in-an-array">this question</a>.</p> <p>Now I have 2 arrays</p> <p>a) Has the various language in (e.g. "en-GB", "fr", "de" etc)<br/> b) Has a suffix of a URL based on the browser language above (e.g. "fr/","de/","uk/")</p> <p>What I am trying to achieve is:</p> <p>1) User hits a page, browser detects which browser it is using from the array (a)<br/> 2) Depending on what the browser is based on (a), it then searches through (b) and if they match, e.g. if the language is "fr" it will use the suffix "fr/" from the array in (b).<br/> 3) It will then add this suffix to a top level domain (which is always constant)<br/><br/> Is this even possible to achieve (I'm sure it is)? Can it be done purely via JavaScript (or JQuery)? How would I go about doing this?</p> <p>Here's some of the code I have so far:</p> <pre><code>var IAB_Array = new Array("de-at","nl-be","fr-be","da","de","hu","en-ie","ga","es","fr","it","nl","no","pl","en","en-GB","en-US","en-gb","en-us"); //language array var IAB_suffix = new Array("at/","be-nl/","be-fr","den/","de/","hu/","ie/","es/","fr/","it/","nl/","nor/","pl/","uk/"); //URL suffix Array var IAB_lang = "en-GB"; //default language var IAB_link = "http://www.mysitegoeshere/"; if(navigator.browserLanguage) IAB_lang = navigator.browserLanguage; //change lang if detection supported if(window.navigator.language) IAB_lang = window.navigator.language; //change lang if detection supported function IAB_Lang_detect () { //execute search for (var i=0;i&lt;IAB_Array.length;i++) { if(IAB_Array[i]==IAB_lang) { document.write(IAB_Array[i]); //output matched array value } } return false; } var IAB_URL = "&lt;a href="+IAB_link+IAB_suffix[1]+"&gt;"+IAB_link+IAB_suffix[1]+"&lt;/a&gt;"; //this is the resulting URL document.write(IAB_URL); IAB_Lang_detect (); </code></pre> <p>I hope someone can help as I'm a little confused! It's more so the matching the values from the 2 arrays and then subsequently selecting the correct suffix that I'm having trouble with.</p> <p>Thanks</p>