title: How to get the value of the a javascript object collection?
body: <p>I am having an undefined value from the object collection when is to display the message. </p>
  
  <p>I should get the value and display it. </p>
  
  <p>Does anybody know what is the problem or I am perhaps missing something?</p>
  
  <p>link full code - <a href="https://jsfiddle.net/lmanhaes/cq1g5dyt/1/" rel="nofollow noreferrer">https://jsfiddle.net/lmanhaes/cq1g5dyt/1/</a></p>
  
  <p>thanks.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>const ratesValue = [{
      "key": "Pound Sterling",
      "value": 1.30,
    },
    {
      "key": "Euro",
      "value": 1.30,
    },
    {
      "key": "Yen",
      "value": 142.72,
    },
    {
      "key": "Yuan",
      "value": 8.95,
    },
    {
      "key": "Swiss Franc",
      "value": 1.26,
    },
    {
      "key": "Canadian Dollar",
      "value": 1.69,
    },
  
  ];
  
  
  function getCurrency() {
    let cur_type = document.getElementById('currencies').value.trim()
    // trim() method to remove whitespaces and present clean and optimal string
  
    let msg = cur_type ? "One US Dollar buys you " + ratesValue[cur_type] + " " + cur_type : ""
    document.getElementById("exchangerate").innerHTML = msg
  }
  
  // event handler -- put in place to be used when value selected from dropdown list.
  window.onload = function () {
    getCurrency();
  
  };</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;h1&gt;Currency Exchange Rates to US Dollar&lt;/h1&gt;
  &lt;!--value of an element has been changed.--&gt;
  &lt;select id="currencies" onchange="getCurrency()"&gt;
    &lt;option value=""&gt;Select a currency&lt;/option&gt;
    &lt;option&gt;Pound Sterling&lt;/option&gt;
    &lt;option&gt;Euro&lt;/option&gt;
    &lt;option&gt;Yen&lt;/option&gt;
    &lt;option&gt;Yuan&lt;/option&gt;
    &lt;option&gt;Swiss Franc&lt;/option&gt;
    &lt;option&gt;Canadian Dollar&lt;/option&gt;
  &lt;/select&gt;
  &lt;p id="exchangerate"&gt;&lt;/p&gt;</code></pre>
  </div>
  </div>
  </p>