title: CLDR/Globalize: slice JSON array: Uncaught TypeError: Cannot read property '0' of undefined
body: <p>We are trying to use <a href="https://github.com/rxaviers/cldrjs" rel="nofollow noreferrer">cldr</a>/<a href="https://github.com/globalizejs/globalize" rel="nofollow noreferrer">globalize</a>; </p>
  
  <p>an exception is triggered while loading 13 CLDR' json files (like likelySubtags.json).</p>
  
  <p>It seems that the size of the 'arguments' is 14 (instead of 13) which triggers the exception "Uncaught TypeError: Cannot read property '0' of undefined"</p>
  
  <p>They are several examples using the same 'JavaScript' code and it doesn't seem that people complain; see <a href="https://github.com/rxaviers/cldrjs/issues/45" rel="nofollow noreferrer">A</a>, <a href="https://gist.github.com/pparadis/d8643555f5ba11bb824c60094745f4b1" rel="nofollow noreferrer">B</a>, <a href="https://js.devexpress.com/Documentation/16_1/Guide/Common/DevExtreme_Packages/" rel="nofollow noreferrer">C</a>, <a href="https://www.devexpress.com/Support/Center/Question/Details/T416777" rel="nofollow noreferrer">D</a> and <a href="https://stackoverflow.com/questions/32753888/jquery-globalize-setup-using-plain-javascript-uncaught-error/33278559#33278559">E</a></p>
  
  <p>Do you need further info? Do you need more code? Just let me know</p>
  
  <hr>
  
  <p><a href="https://i.stack.imgur.com/djmQb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/djmQb.png" alt="Uncaught TypeError: Cannot read property &#39;0&#39; of undefined"></a></p>
  
  <p><strong>JavaScript, load cldr data, set locale to 'en'</strong></p>
  
  <pre><code>$(document).ready(function () {
    // https://stackoverflow.com/questions/35863853/using-jquery-globalize-with-mvc-5
    // download json files on https://github.com/unicode-cldr?page=2
    // how to setup globalize, cldr and json data: http://johnnyreilly.github.io/globalize-so-what-cha-want
  
    var locale = 'en'; // TODO: manage the localization based on user preferences (browser)
  
    // https://stackoverflow.com/questions/32586551/what-is-the-best-way-to-handle-validation-with-different-culture
    $.when(
        $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/likelySubtags.json"),
        $.getJSON("/Scripts/plugins/cldr-numbers-full-30.0.2/main/" + locale + "/numbers.json"),
        $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/numberingSystems.json"),
        $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/plurals.json"),
        $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/ordinals.json"),
        $.getJSON("/Scripts/plugins/cldr-numbers-full-30.0.2/main/" + locale + "/currencies.json"),
        $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/currencyData.json"),
        $.getJSON("/Scripts/plugins/cldr-dates-full-30.0.2/main/" + locale + "/ca-gregorian.json"),
        $.getJSON("/Scripts/plugins/cldr-dates-full-30.0.2/main/" + locale + "/timeZoneNames.json"),
        $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/timeData.json"),
        $.getJSON("/Scripts/plugins/cldr-core-30.0.2/supplemental/weekData.json"),
        $.getJSON("/Scripts/plugins/cldr-dates-full-30.0.2/main/" + locale + "/dateFields.json"),
        $.getJSON("/Scripts/plugins/cldr-units-full-30.0.2/main/" + locale + "/units.json"),
        console.log("JSONs loaded")
        ).then(function () {
          console.log("start slicing");
          return [].slice.apply(arguments, [0]).map(function (result) {
            console.log("slicing done");
            return result[0];
          });
        }).then(Globalize.load).then(function () {
          Globalize.locale(locale);
          console.log("Locale set to " + locale);
        }).then(console.log("LOADED EVERYTHING"));
  
  
  });
  </code></pre>
  
  <p><strong>HTML , load the javascripts</strong></p>
  
  <pre><code>&lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;title&gt;StratEx | Project management&lt;/title&gt;
    &lt;meta http-equiv="X-UA-Compatible" content="IE=EDGE"&gt;
    &lt;link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css"&gt;
    &lt;link href="/Scripts/plugins/jquery-ui-1.11.4/jquery-ui.css" rel="stylesheet"&gt;
  
    &lt;link href="/Content/font-awesome/css/font-awesome.css" rel="stylesheet"&gt;
  
    &lt;link href="/Content/bootstrap-3.3.7/css/bootstrap.css" rel="stylesheet"&gt;
  
    &lt;link href="/Content/animate.css" rel="stylesheet"&gt;
    &lt;link href="/Content/style.css" rel="stylesheet"&gt;
  
    &lt;link href="/Content/themes/redmond/jquery-ui-1.10.3.custom.min.css" rel="stylesheet"&gt;
  
    &lt;script type="application/javascript" async="" defer="" src="https://by2.uservoice.com/t2/ID/web/ID/track.js?_=TIMESTAMP&amp;amp;s=1&amp;amp;c=__uvSessionData0&amp;amp;d=HASH"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" async="" src="//widget.uservoice.com/CODE.js"&gt;&lt;/script&gt;&lt;script async="" src="//www.google-analytics.com/analytics.js"&gt;&lt;/script&gt;
    &lt;script
      src="/Scripts/jquery-2.2.1.js"&gt;&lt;/script&gt;
  
      &lt;script src="/Scripts/plugins/cldrjs-0.4.7/dist/cldr.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/cldrjs-0.4.7/dist/cldr/event.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/cldrjs-0.4.7/dist/cldr/supplemental.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/globalize-1.1.2/dist/globalize.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/number.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/plural.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/message.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/currency.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/date.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/relative-time.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/globalize-1.1.2/dist/globalize/unit.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/jquery-validation-1.15.1/dist/jquery.validate.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/jquery-validation-unobtrusive-3.2.6/jquery.validate.unobtrusive.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/jquery-ajax-unobtrusive-3.2.4/jquery.unobtrusive-ajax.js"&gt;&lt;/script&gt;
      &lt;script src="/Scripts/plugins/jquery-validation-globalize-1.0.0/jquery.validate.globalize.js"&gt;&lt;/script&gt;
  
      &lt;script src="/Scripts/plugins/jquery-ui-1.11.4/jquery-ui.js"&gt;&lt;/script&gt;
  
      &lt;script src="/Content/bootstrap-3.3.7/js/bootstrap.js"&gt;&lt;/script&gt;
  
  &lt;/head&gt;
  </code></pre>