title: jQuery search in an object using a string
body: <h1>UPDATE</h1>
  
  <p><strong>23 November 2016:</strong></p>
  
  <p>I was very close to the solution. Rory McCrossan has solved it for me, so I accepted his answer. <strong>BUT</strong> I changed the code for faster developing. I want to share this so you can use it to.</p>
  
  <p><br></p>
  
  <p><strong>JSON</strong> <em>langfile-v1.0.json</em></p>
  
  <pre><code>{
      "nl": {
          "text1":"Hallo Wereld!",
          "text2":"voorbeeld.com",
          "text3":"Ik hou van Stack Overflow"
      },
      "en":{
          "text1":"Hello World!",
          "text2":"example.com",
          "text3":"I love Stack Overflow"
      }
  }
  </code></pre>
  
  <p><br></p>
  
  <p><strong>Javascript / jQuery</strong> <em>script.js</em></p>
  
  <pre><code>//Creating an GLOBAL object
  var languageObject;
  
  //Get the language json file
  $.get("langfile-v1.0.json", function(response){
      languageObject = response; //Assign the response to the GLOBAL object
      setLanguage(); //Calling the setLanguage() function
  });
  
  //Call this function to set the language
  function setLanguage() {
      $("lang").html(function() {
          var userLang = navigator.language || navigator.userLanguage;
          var langSupported = false; //Check if the user language is supported
          $.each(languageObject, function(key) {
              if (userLang == key) {
                  langSupported = true;
              }
          });
          if (langSupported) {
              //Users language is supported, use that language
              return languageObject[userLang][$(this).html()];
          } else {
              //User language is NOT supported, use default language
              return languageObject.en[$(this).html()];
          }
      });
  }
  </code></pre>
  
  <p><br></p>
  
  <p><strong>HTML</strong> <em>page.html</em></p>
  
  <pre><code>&lt;lang&gt;text1&lt;/lang&gt; &lt;br&gt;
  &lt;lang&gt;text2&lt;/lang&gt; &lt;br&gt;
  &lt;lang&gt;text3&lt;/lang&gt;
  </code></pre>
  
  <p><br></p>
  
  <h1>Demo</h1>
  
  <p>You can check how this works on JSFiddle (with a slightly different code because I dont know how to inculde the <em>langfile-v1.0.json</em> file)</p>
  
  <p><br>
  <a href="https://jsfiddle.net/promike360/2evjyfah/" rel="nofollow noreferrer">Click here for demo</a></p>
  
  <hr>
  
  <h1>OLD QUESTION POST:</h1>
  
  <p>I want to search in a object using a string.</p>
  
  <h1>Example:</h1>
  
  <p><strong>JSON</strong></p>
  
  <pre><code>{
      "nl": {
          "lang":"Nederlands",
          "header-WelcomeText":"Welkom op de website",
          "header-Sub1":"Hoofdpaneel"
      },
      "en": {
          "lang":"English",
          "header-WelcomeText":"Welcome on the website",
          "header-Sub1":"Dashboard"
      }
  }
  </code></pre>
  
  <p><strong>Javascript/jQuery</strong></p>
  
  <pre><code>var output;
  $.get("file.json", function(response){
      output = response; //This is now a object in javascript
  });
  </code></pre>
  
  <p>This all works, here what i want:</p>
  
  <pre><code>//The jQuery code
  $('span .lang').text(output.nl.$(this).attr("data-lang"));
  
  //The HTML code
  &lt;span class="lang" data-lang="header-Sub1"&gt;&lt;/span&gt;
  </code></pre>
  
  <p>I know this will not work, but I know there will be a way to achief this.</p>