title: What is the most 'pure JavaScript' way to write my function, to reduce the execution time?
body: <pre><code>var AcceptLngs = ['de', 'en', 'es', 'fr', 'it', 'pt', 'pt-BR'],
      _getI18N = { 
          'wordToTranslate' : {
              'pt' : `translatedWord`,
              [...]
          },
          '2ndWordToTranslate' : {
              'pt-BR' : `translatedWord`,
              [...]
           }
      },
      nav = window.navigator,
      navLng = nav.language || nav.browserLanguage || nav.userLanguage,
      prefs = nav.languages,
      navPrefLng = prefs[0],
      defaultLng = 'en',
      lng = navLng, //It must be set for translation
  
      // CHECK THE LANGUAGE OF THE NAVIGATOR.
      checkLng = function checkLng() {
          // isL10nAvailable:
          if (AcceptLngs.indexOf(navPrefLng) &lt; -1) {
              lng = navPrefLng;
              return lng;
          }
      },
      // SEARCH IF LANGUAGE OF THE APP IS AVAILABLE.
      isLngDispo = function isLngDispo() {
          // isSubstrL10nAvailable:
          checkLng();
          if (AcceptLngs.indexOf(navPrefLng) === -1) {
              lng = navPrefLng.substring(0,2);
              return lng;
          }
      },
      // SEARCH IF LANGUAGE OF THE APP IS AVAILABLE.
      setLng = function setLng() {
          // isL10nNoAvailable:
          isLngDispo();
          if (AcceptLngs.indexOf(lng) === -1) {
              lng = defaultLng;
              return lng;
          }
      };
      // APPLYING LANGUAGE FOR THE APP.
      setLng();
  </code></pre>
  
  <p>I am beginner in JavaScript. My script works. The problem is its execution time. I go from 102 ms (without the translation) to 448 ms (with).</p>
  
  <p>I have try with loop, but I didn't manage to make it work properly. He didn't detect the language in <code>AcceptedLng</code> and automatically put me the nav.language.</p>
  
  <p>Perhaps, more simply, I should search directly in '_getI18N', but I have not yet gotten familiar with the search in the arrays, and I can not get any results either.</p>
  
  <p>Info: To translate, I use   _getI18N[<code>wordToTranslate</code>][lng]  into my script.</p>