Array.from on the Internet Explorer












26















I have a problem with my angular app on the Internet Explorer. It runs everywhere without a problem (Chrome, Mozilla, Edge), but on on the IE.



I have analyzed with the Developer Explorer where the error is and it returned that the error occurs on the following line:



myDataSet[index - 1].data = Array.from(tmp);



Where this is the following error message I am getting:



Object does not support property or method from at Anonymous function....(etc.)



What I am doing there is that I have a Set() named tmp which contains the following data:



enter image description here



Afterwards I am simply creating a simple array object from this Set.



How can I solve this problem?



EDIT



Based on the recommendations I have added the following code to my app:



if (!Array.from) {
Array.from = (function () {
var toStr = Object.prototype.toString;
var isCallable = function (fn) {
return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
};
var toInteger = function (value) {
var number = Number(value);
if (isNaN(number)) { return 0; }
if (number === 0 || !isFinite(number)) { return number; }
return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
};
var maxSafeInteger = Math.pow(2, 53) - 1;
var toLength = function (value) {
var len = toInteger(value);
return Math.min(Math.max(len, 0), maxSafeInteger);
};

// The length property of the from method is 1.
return function from(arrayLike/*, mapFn, thisArg */) {
// 1. Let C be the this value.
var C = this;

// 2. Let items be ToObject(arrayLike).
var items = Object(arrayLike);

// 3. ReturnIfAbrupt(items).
if (arrayLike == null) {
throw new TypeError("Array.from requires an array-like object - not null or undefined");
}

// 4. If mapfn is undefined, then let mapping be false.
var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
var T;
if (typeof mapFn !== 'undefined') {
// 5. else
// 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
if (!isCallable(mapFn)) {
throw new TypeError('Array.from: when provided, the second argument must be a function');
}

// 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
if (arguments.length > 2) {
T = arguments[2];
}
}

// 10. Let lenValue be Get(items, "length").
// 11. Let len be ToLength(lenValue).
var len = toLength(items.length);

// 13. If IsConstructor(C) is true, then
// 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
// 14. a. Else, Let A be ArrayCreate(len).
var A = isCallable(C) ? Object(new C(len)) : new Array(len);

// 16. Let k be 0.
var k = 0;
// 17. Repeat, while k < len… (also steps a - h)
var kValue;
while (k < len) {
kValue = items[k];
if (mapFn) {
A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
} else {
A[k] = kValue;
}
k += 1;
}
// 18. Let putStatus be Put(A, "length", len, true).
A.length = len;
// 20. Return A.
return A;
};
}());
}









share|improve this question





























    26















    I have a problem with my angular app on the Internet Explorer. It runs everywhere without a problem (Chrome, Mozilla, Edge), but on on the IE.



    I have analyzed with the Developer Explorer where the error is and it returned that the error occurs on the following line:



    myDataSet[index - 1].data = Array.from(tmp);



    Where this is the following error message I am getting:



    Object does not support property or method from at Anonymous function....(etc.)



    What I am doing there is that I have a Set() named tmp which contains the following data:



    enter image description here



    Afterwards I am simply creating a simple array object from this Set.



    How can I solve this problem?



    EDIT



    Based on the recommendations I have added the following code to my app:



    if (!Array.from) {
    Array.from = (function () {
    var toStr = Object.prototype.toString;
    var isCallable = function (fn) {
    return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
    };
    var toInteger = function (value) {
    var number = Number(value);
    if (isNaN(number)) { return 0; }
    if (number === 0 || !isFinite(number)) { return number; }
    return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
    };
    var maxSafeInteger = Math.pow(2, 53) - 1;
    var toLength = function (value) {
    var len = toInteger(value);
    return Math.min(Math.max(len, 0), maxSafeInteger);
    };

    // The length property of the from method is 1.
    return function from(arrayLike/*, mapFn, thisArg */) {
    // 1. Let C be the this value.
    var C = this;

    // 2. Let items be ToObject(arrayLike).
    var items = Object(arrayLike);

    // 3. ReturnIfAbrupt(items).
    if (arrayLike == null) {
    throw new TypeError("Array.from requires an array-like object - not null or undefined");
    }

    // 4. If mapfn is undefined, then let mapping be false.
    var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
    var T;
    if (typeof mapFn !== 'undefined') {
    // 5. else
    // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
    if (!isCallable(mapFn)) {
    throw new TypeError('Array.from: when provided, the second argument must be a function');
    }

    // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
    if (arguments.length > 2) {
    T = arguments[2];
    }
    }

    // 10. Let lenValue be Get(items, "length").
    // 11. Let len be ToLength(lenValue).
    var len = toLength(items.length);

    // 13. If IsConstructor(C) is true, then
    // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
    // 14. a. Else, Let A be ArrayCreate(len).
    var A = isCallable(C) ? Object(new C(len)) : new Array(len);

    // 16. Let k be 0.
    var k = 0;
    // 17. Repeat, while k < len… (also steps a - h)
    var kValue;
    while (k < len) {
    kValue = items[k];
    if (mapFn) {
    A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
    } else {
    A[k] = kValue;
    }
    k += 1;
    }
    // 18. Let putStatus be Put(A, "length", len, true).
    A.length = len;
    // 20. Return A.
    return A;
    };
    }());
    }









    share|improve this question



























      26












      26








      26


      7






      I have a problem with my angular app on the Internet Explorer. It runs everywhere without a problem (Chrome, Mozilla, Edge), but on on the IE.



      I have analyzed with the Developer Explorer where the error is and it returned that the error occurs on the following line:



      myDataSet[index - 1].data = Array.from(tmp);



      Where this is the following error message I am getting:



      Object does not support property or method from at Anonymous function....(etc.)



      What I am doing there is that I have a Set() named tmp which contains the following data:



      enter image description here



      Afterwards I am simply creating a simple array object from this Set.



      How can I solve this problem?



      EDIT



      Based on the recommendations I have added the following code to my app:



      if (!Array.from) {
      Array.from = (function () {
      var toStr = Object.prototype.toString;
      var isCallable = function (fn) {
      return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
      };
      var toInteger = function (value) {
      var number = Number(value);
      if (isNaN(number)) { return 0; }
      if (number === 0 || !isFinite(number)) { return number; }
      return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
      };
      var maxSafeInteger = Math.pow(2, 53) - 1;
      var toLength = function (value) {
      var len = toInteger(value);
      return Math.min(Math.max(len, 0), maxSafeInteger);
      };

      // The length property of the from method is 1.
      return function from(arrayLike/*, mapFn, thisArg */) {
      // 1. Let C be the this value.
      var C = this;

      // 2. Let items be ToObject(arrayLike).
      var items = Object(arrayLike);

      // 3. ReturnIfAbrupt(items).
      if (arrayLike == null) {
      throw new TypeError("Array.from requires an array-like object - not null or undefined");
      }

      // 4. If mapfn is undefined, then let mapping be false.
      var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
      var T;
      if (typeof mapFn !== 'undefined') {
      // 5. else
      // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
      if (!isCallable(mapFn)) {
      throw new TypeError('Array.from: when provided, the second argument must be a function');
      }

      // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
      if (arguments.length > 2) {
      T = arguments[2];
      }
      }

      // 10. Let lenValue be Get(items, "length").
      // 11. Let len be ToLength(lenValue).
      var len = toLength(items.length);

      // 13. If IsConstructor(C) is true, then
      // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
      // 14. a. Else, Let A be ArrayCreate(len).
      var A = isCallable(C) ? Object(new C(len)) : new Array(len);

      // 16. Let k be 0.
      var k = 0;
      // 17. Repeat, while k < len… (also steps a - h)
      var kValue;
      while (k < len) {
      kValue = items[k];
      if (mapFn) {
      A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
      } else {
      A[k] = kValue;
      }
      k += 1;
      }
      // 18. Let putStatus be Put(A, "length", len, true).
      A.length = len;
      // 20. Return A.
      return A;
      };
      }());
      }









      share|improve this question
















      I have a problem with my angular app on the Internet Explorer. It runs everywhere without a problem (Chrome, Mozilla, Edge), but on on the IE.



      I have analyzed with the Developer Explorer where the error is and it returned that the error occurs on the following line:



      myDataSet[index - 1].data = Array.from(tmp);



      Where this is the following error message I am getting:



      Object does not support property or method from at Anonymous function....(etc.)



      What I am doing there is that I have a Set() named tmp which contains the following data:



      enter image description here



      Afterwards I am simply creating a simple array object from this Set.



      How can I solve this problem?



      EDIT



      Based on the recommendations I have added the following code to my app:



      if (!Array.from) {
      Array.from = (function () {
      var toStr = Object.prototype.toString;
      var isCallable = function (fn) {
      return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
      };
      var toInteger = function (value) {
      var number = Number(value);
      if (isNaN(number)) { return 0; }
      if (number === 0 || !isFinite(number)) { return number; }
      return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
      };
      var maxSafeInteger = Math.pow(2, 53) - 1;
      var toLength = function (value) {
      var len = toInteger(value);
      return Math.min(Math.max(len, 0), maxSafeInteger);
      };

      // The length property of the from method is 1.
      return function from(arrayLike/*, mapFn, thisArg */) {
      // 1. Let C be the this value.
      var C = this;

      // 2. Let items be ToObject(arrayLike).
      var items = Object(arrayLike);

      // 3. ReturnIfAbrupt(items).
      if (arrayLike == null) {
      throw new TypeError("Array.from requires an array-like object - not null or undefined");
      }

      // 4. If mapfn is undefined, then let mapping be false.
      var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
      var T;
      if (typeof mapFn !== 'undefined') {
      // 5. else
      // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
      if (!isCallable(mapFn)) {
      throw new TypeError('Array.from: when provided, the second argument must be a function');
      }

      // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
      if (arguments.length > 2) {
      T = arguments[2];
      }
      }

      // 10. Let lenValue be Get(items, "length").
      // 11. Let len be ToLength(lenValue).
      var len = toLength(items.length);

      // 13. If IsConstructor(C) is true, then
      // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
      // 14. a. Else, Let A be ArrayCreate(len).
      var A = isCallable(C) ? Object(new C(len)) : new Array(len);

      // 16. Let k be 0.
      var k = 0;
      // 17. Repeat, while k < len… (also steps a - h)
      var kValue;
      while (k < len) {
      kValue = items[k];
      if (mapFn) {
      A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
      } else {
      A[k] = kValue;
      }
      k += 1;
      }
      // 18. Let putStatus be Put(A, "length", len, true).
      A.length = len;
      // 20. Return A.
      return A;
      };
      }());
      }






      javascript arrays angularjs internet-explorer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Apr 23 '16 at 12:46







      Robert J.

















      asked Apr 23 '16 at 12:40









      Robert J.Robert J.

      1,18011631




      1,18011631
























          3 Answers
          3






          active

          oldest

          votes


















          40














          Array.from not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.



          Just add the code below to your page (JS code was copied from developer.mozilla.org). It will emulate an ES6's Array.from method.




          Array.from was added to the ECMA-262 standard in the 6th edition; as
          such it may not be present in other implementations of the standard.
          You can work around this by inserting the following code at the
          beginning of your scripts, allowing use of Array.from in
          implementations that don't natively support it. This algorithm is
          exactly the one specified in ECMA-262, 6th edition, assuming Object
          and TypeError have their original values and that callback.call
          evaluates to the original value of Function.prototype.call. In
          addition, since true iterables can not be polyfilled, this
          implementation does not support generic iterables as defined in the
          6th edition of ECMA-262.




          if (!Array.from) {
          Array.from = (function () {
          var toStr = Object.prototype.toString;
          var isCallable = function (fn) {
          return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
          };
          var toInteger = function (value) {
          var number = Number(value);
          if (isNaN(number)) { return 0; }
          if (number === 0 || !isFinite(number)) { return number; }
          return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
          };
          var maxSafeInteger = Math.pow(2, 53) - 1;
          var toLength = function (value) {
          var len = toInteger(value);
          return Math.min(Math.max(len, 0), maxSafeInteger);
          };

          // The length property of the from method is 1.
          return function from(arrayLike/*, mapFn, thisArg */) {
          // 1. Let C be the this value.
          var C = this;

          // 2. Let items be ToObject(arrayLike).
          var items = Object(arrayLike);

          // 3. ReturnIfAbrupt(items).
          if (arrayLike == null) {
          throw new TypeError("Array.from requires an array-like object - not null or undefined");
          }

          // 4. If mapfn is undefined, then let mapping be false.
          var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
          var T;
          if (typeof mapFn !== 'undefined') {
          // 5. else
          // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
          if (!isCallable(mapFn)) {
          throw new TypeError('Array.from: when provided, the second argument must be a function');
          }

          // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
          if (arguments.length > 2) {
          T = arguments[2];
          }
          }

          // 10. Let lenValue be Get(items, "length").
          // 11. Let len be ToLength(lenValue).
          var len = toLength(items.length);

          // 13. If IsConstructor(C) is true, then
          // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
          // 14. a. Else, Let A be ArrayCreate(len).
          var A = isCallable(C) ? Object(new C(len)) : new Array(len);

          // 16. Let k be 0.
          var k = 0;
          // 17. Repeat, while k < len… (also steps a - h)
          var kValue;
          while (k < len) {
          kValue = items[k];
          if (mapFn) {
          A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
          } else {
          A[k] = kValue;
          }
          k += 1;
          }
          // 18. Let putStatus be Put(A, "length", len, true).
          A.length = len;
          // 20. Return A.
          return A;
          };
          }());
          }





          share|improve this answer





















          • 1





            thank you for explaining this. Could you advise, what code to use to replace my Array.from, please?

            – Robert J.
            Apr 23 '16 at 12:43













          • I have updated my answer. Just copy JavaScript code into your page. For example to the main JS file. And your problem will be solved!

            – Ali Mamedov
            Apr 23 '16 at 12:51











          • You may try myDataSet[index - 1].data = Array.prototype.slice.call(tmp);

            – Redu
            Apr 23 '16 at 12:51











          • I have tried to use your line but it did not work on my end. When using Array.From I have noticed that the function has issues when I am passing a Set to it (e.g. id does not recognize lenght of the array, mapFn is undefined, ...)

            – Robert J.
            Apr 23 '16 at 13:02











          • @Robert J. if tmp object does not have a length property first try inserting a length property to it and give it a correct value. If it doesn't work you have to make the tmp object iterable by inserting a [Symbol.iterator] method. (study this developer.mozilla.org/tr/docs/Web/JavaScript/Reference/…) once tmp is an iterable object then you can safely use myDataSet[index - 1].data = Array.prototype.slice.call(tmp); method. Could you please list the tmp object in the question.

            – Redu
            Apr 23 '16 at 13:12





















          6














          I faced the same issue. Looked at the polyfill and it is threatening huge. Here is 2 lines short solution.



          The OP basically needs to create simple array from his array-like object. I used to my taste the most efficient 2 lines plain for loop (I had to make array from HTML DOM nodelist array-like object, same applicable to JavaScript arguments object).



          For the OP's case it could sound this way:



          var temp_array = ,
          length = tmp.length;

          for (var i = 0; i < length; i++) {
          temp_array.push(tmp[i]);
          }

          // Here you get the normal array "temp_array" containing all items
          // from your `tmp` Set.


          Make it separate function and you get 3 lines universal reusable solution for the IE<9 case.



          Here is how the separate function may look like:



          /**
          * @param arr The array | array-like data structure.
          * @param callback The function to process each element in the 'arr'.
          * The callback signature and usage is assumed similar to the
          * native JS 'forEach' callback argument usage.
          */
          function customEach(arr, callback) {
          'use strict';
          var l = arr.length;
          for (var i = 0; i < l; i++) {
          callback(arr[i], i, arr);
          }
          };


          PS: here is the relevant description for forEach callback to see how to use the customEach callback.






          share|improve this answer

































            4














            While it's not supported on IE, you may use the polyfill from MDN.






            share|improve this answer
























              Your Answer






              StackExchange.ifUsing("editor", function () {
              StackExchange.using("externalEditor", function () {
              StackExchange.using("snippets", function () {
              StackExchange.snippets.init();
              });
              });
              }, "code-snippets");

              StackExchange.ready(function() {
              var channelOptions = {
              tags: "".split(" "),
              id: "1"
              };
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function() {
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled) {
              StackExchange.using("snippets", function() {
              createEditor();
              });
              }
              else {
              createEditor();
              }
              });

              function createEditor() {
              StackExchange.prepareEditor({
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              });


              }
              });














              draft saved

              draft discarded


















              StackExchange.ready(
              function () {
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36810940%2farray-from-on-the-internet-explorer%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              40














              Array.from not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.



              Just add the code below to your page (JS code was copied from developer.mozilla.org). It will emulate an ES6's Array.from method.




              Array.from was added to the ECMA-262 standard in the 6th edition; as
              such it may not be present in other implementations of the standard.
              You can work around this by inserting the following code at the
              beginning of your scripts, allowing use of Array.from in
              implementations that don't natively support it. This algorithm is
              exactly the one specified in ECMA-262, 6th edition, assuming Object
              and TypeError have their original values and that callback.call
              evaluates to the original value of Function.prototype.call. In
              addition, since true iterables can not be polyfilled, this
              implementation does not support generic iterables as defined in the
              6th edition of ECMA-262.




              if (!Array.from) {
              Array.from = (function () {
              var toStr = Object.prototype.toString;
              var isCallable = function (fn) {
              return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
              };
              var toInteger = function (value) {
              var number = Number(value);
              if (isNaN(number)) { return 0; }
              if (number === 0 || !isFinite(number)) { return number; }
              return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
              };
              var maxSafeInteger = Math.pow(2, 53) - 1;
              var toLength = function (value) {
              var len = toInteger(value);
              return Math.min(Math.max(len, 0), maxSafeInteger);
              };

              // The length property of the from method is 1.
              return function from(arrayLike/*, mapFn, thisArg */) {
              // 1. Let C be the this value.
              var C = this;

              // 2. Let items be ToObject(arrayLike).
              var items = Object(arrayLike);

              // 3. ReturnIfAbrupt(items).
              if (arrayLike == null) {
              throw new TypeError("Array.from requires an array-like object - not null or undefined");
              }

              // 4. If mapfn is undefined, then let mapping be false.
              var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
              var T;
              if (typeof mapFn !== 'undefined') {
              // 5. else
              // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
              if (!isCallable(mapFn)) {
              throw new TypeError('Array.from: when provided, the second argument must be a function');
              }

              // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
              if (arguments.length > 2) {
              T = arguments[2];
              }
              }

              // 10. Let lenValue be Get(items, "length").
              // 11. Let len be ToLength(lenValue).
              var len = toLength(items.length);

              // 13. If IsConstructor(C) is true, then
              // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
              // 14. a. Else, Let A be ArrayCreate(len).
              var A = isCallable(C) ? Object(new C(len)) : new Array(len);

              // 16. Let k be 0.
              var k = 0;
              // 17. Repeat, while k < len… (also steps a - h)
              var kValue;
              while (k < len) {
              kValue = items[k];
              if (mapFn) {
              A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
              } else {
              A[k] = kValue;
              }
              k += 1;
              }
              // 18. Let putStatus be Put(A, "length", len, true).
              A.length = len;
              // 20. Return A.
              return A;
              };
              }());
              }





              share|improve this answer





















              • 1





                thank you for explaining this. Could you advise, what code to use to replace my Array.from, please?

                – Robert J.
                Apr 23 '16 at 12:43













              • I have updated my answer. Just copy JavaScript code into your page. For example to the main JS file. And your problem will be solved!

                – Ali Mamedov
                Apr 23 '16 at 12:51











              • You may try myDataSet[index - 1].data = Array.prototype.slice.call(tmp);

                – Redu
                Apr 23 '16 at 12:51











              • I have tried to use your line but it did not work on my end. When using Array.From I have noticed that the function has issues when I am passing a Set to it (e.g. id does not recognize lenght of the array, mapFn is undefined, ...)

                – Robert J.
                Apr 23 '16 at 13:02











              • @Robert J. if tmp object does not have a length property first try inserting a length property to it and give it a correct value. If it doesn't work you have to make the tmp object iterable by inserting a [Symbol.iterator] method. (study this developer.mozilla.org/tr/docs/Web/JavaScript/Reference/…) once tmp is an iterable object then you can safely use myDataSet[index - 1].data = Array.prototype.slice.call(tmp); method. Could you please list the tmp object in the question.

                – Redu
                Apr 23 '16 at 13:12


















              40














              Array.from not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.



              Just add the code below to your page (JS code was copied from developer.mozilla.org). It will emulate an ES6's Array.from method.




              Array.from was added to the ECMA-262 standard in the 6th edition; as
              such it may not be present in other implementations of the standard.
              You can work around this by inserting the following code at the
              beginning of your scripts, allowing use of Array.from in
              implementations that don't natively support it. This algorithm is
              exactly the one specified in ECMA-262, 6th edition, assuming Object
              and TypeError have their original values and that callback.call
              evaluates to the original value of Function.prototype.call. In
              addition, since true iterables can not be polyfilled, this
              implementation does not support generic iterables as defined in the
              6th edition of ECMA-262.




              if (!Array.from) {
              Array.from = (function () {
              var toStr = Object.prototype.toString;
              var isCallable = function (fn) {
              return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
              };
              var toInteger = function (value) {
              var number = Number(value);
              if (isNaN(number)) { return 0; }
              if (number === 0 || !isFinite(number)) { return number; }
              return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
              };
              var maxSafeInteger = Math.pow(2, 53) - 1;
              var toLength = function (value) {
              var len = toInteger(value);
              return Math.min(Math.max(len, 0), maxSafeInteger);
              };

              // The length property of the from method is 1.
              return function from(arrayLike/*, mapFn, thisArg */) {
              // 1. Let C be the this value.
              var C = this;

              // 2. Let items be ToObject(arrayLike).
              var items = Object(arrayLike);

              // 3. ReturnIfAbrupt(items).
              if (arrayLike == null) {
              throw new TypeError("Array.from requires an array-like object - not null or undefined");
              }

              // 4. If mapfn is undefined, then let mapping be false.
              var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
              var T;
              if (typeof mapFn !== 'undefined') {
              // 5. else
              // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
              if (!isCallable(mapFn)) {
              throw new TypeError('Array.from: when provided, the second argument must be a function');
              }

              // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
              if (arguments.length > 2) {
              T = arguments[2];
              }
              }

              // 10. Let lenValue be Get(items, "length").
              // 11. Let len be ToLength(lenValue).
              var len = toLength(items.length);

              // 13. If IsConstructor(C) is true, then
              // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
              // 14. a. Else, Let A be ArrayCreate(len).
              var A = isCallable(C) ? Object(new C(len)) : new Array(len);

              // 16. Let k be 0.
              var k = 0;
              // 17. Repeat, while k < len… (also steps a - h)
              var kValue;
              while (k < len) {
              kValue = items[k];
              if (mapFn) {
              A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
              } else {
              A[k] = kValue;
              }
              k += 1;
              }
              // 18. Let putStatus be Put(A, "length", len, true).
              A.length = len;
              // 20. Return A.
              return A;
              };
              }());
              }





              share|improve this answer





















              • 1





                thank you for explaining this. Could you advise, what code to use to replace my Array.from, please?

                – Robert J.
                Apr 23 '16 at 12:43













              • I have updated my answer. Just copy JavaScript code into your page. For example to the main JS file. And your problem will be solved!

                – Ali Mamedov
                Apr 23 '16 at 12:51











              • You may try myDataSet[index - 1].data = Array.prototype.slice.call(tmp);

                – Redu
                Apr 23 '16 at 12:51











              • I have tried to use your line but it did not work on my end. When using Array.From I have noticed that the function has issues when I am passing a Set to it (e.g. id does not recognize lenght of the array, mapFn is undefined, ...)

                – Robert J.
                Apr 23 '16 at 13:02











              • @Robert J. if tmp object does not have a length property first try inserting a length property to it and give it a correct value. If it doesn't work you have to make the tmp object iterable by inserting a [Symbol.iterator] method. (study this developer.mozilla.org/tr/docs/Web/JavaScript/Reference/…) once tmp is an iterable object then you can safely use myDataSet[index - 1].data = Array.prototype.slice.call(tmp); method. Could you please list the tmp object in the question.

                – Redu
                Apr 23 '16 at 13:12
















              40












              40








              40







              Array.from not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.



              Just add the code below to your page (JS code was copied from developer.mozilla.org). It will emulate an ES6's Array.from method.




              Array.from was added to the ECMA-262 standard in the 6th edition; as
              such it may not be present in other implementations of the standard.
              You can work around this by inserting the following code at the
              beginning of your scripts, allowing use of Array.from in
              implementations that don't natively support it. This algorithm is
              exactly the one specified in ECMA-262, 6th edition, assuming Object
              and TypeError have their original values and that callback.call
              evaluates to the original value of Function.prototype.call. In
              addition, since true iterables can not be polyfilled, this
              implementation does not support generic iterables as defined in the
              6th edition of ECMA-262.




              if (!Array.from) {
              Array.from = (function () {
              var toStr = Object.prototype.toString;
              var isCallable = function (fn) {
              return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
              };
              var toInteger = function (value) {
              var number = Number(value);
              if (isNaN(number)) { return 0; }
              if (number === 0 || !isFinite(number)) { return number; }
              return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
              };
              var maxSafeInteger = Math.pow(2, 53) - 1;
              var toLength = function (value) {
              var len = toInteger(value);
              return Math.min(Math.max(len, 0), maxSafeInteger);
              };

              // The length property of the from method is 1.
              return function from(arrayLike/*, mapFn, thisArg */) {
              // 1. Let C be the this value.
              var C = this;

              // 2. Let items be ToObject(arrayLike).
              var items = Object(arrayLike);

              // 3. ReturnIfAbrupt(items).
              if (arrayLike == null) {
              throw new TypeError("Array.from requires an array-like object - not null or undefined");
              }

              // 4. If mapfn is undefined, then let mapping be false.
              var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
              var T;
              if (typeof mapFn !== 'undefined') {
              // 5. else
              // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
              if (!isCallable(mapFn)) {
              throw new TypeError('Array.from: when provided, the second argument must be a function');
              }

              // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
              if (arguments.length > 2) {
              T = arguments[2];
              }
              }

              // 10. Let lenValue be Get(items, "length").
              // 11. Let len be ToLength(lenValue).
              var len = toLength(items.length);

              // 13. If IsConstructor(C) is true, then
              // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
              // 14. a. Else, Let A be ArrayCreate(len).
              var A = isCallable(C) ? Object(new C(len)) : new Array(len);

              // 16. Let k be 0.
              var k = 0;
              // 17. Repeat, while k < len… (also steps a - h)
              var kValue;
              while (k < len) {
              kValue = items[k];
              if (mapFn) {
              A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
              } else {
              A[k] = kValue;
              }
              k += 1;
              }
              // 18. Let putStatus be Put(A, "length", len, true).
              A.length = len;
              // 20. Return A.
              return A;
              };
              }());
              }





              share|improve this answer















              Array.from not supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Not supported in Windows 8.1.



              Just add the code below to your page (JS code was copied from developer.mozilla.org). It will emulate an ES6's Array.from method.




              Array.from was added to the ECMA-262 standard in the 6th edition; as
              such it may not be present in other implementations of the standard.
              You can work around this by inserting the following code at the
              beginning of your scripts, allowing use of Array.from in
              implementations that don't natively support it. This algorithm is
              exactly the one specified in ECMA-262, 6th edition, assuming Object
              and TypeError have their original values and that callback.call
              evaluates to the original value of Function.prototype.call. In
              addition, since true iterables can not be polyfilled, this
              implementation does not support generic iterables as defined in the
              6th edition of ECMA-262.




              if (!Array.from) {
              Array.from = (function () {
              var toStr = Object.prototype.toString;
              var isCallable = function (fn) {
              return typeof fn === 'function' || toStr.call(fn) === '[object Function]';
              };
              var toInteger = function (value) {
              var number = Number(value);
              if (isNaN(number)) { return 0; }
              if (number === 0 || !isFinite(number)) { return number; }
              return (number > 0 ? 1 : -1) * Math.floor(Math.abs(number));
              };
              var maxSafeInteger = Math.pow(2, 53) - 1;
              var toLength = function (value) {
              var len = toInteger(value);
              return Math.min(Math.max(len, 0), maxSafeInteger);
              };

              // The length property of the from method is 1.
              return function from(arrayLike/*, mapFn, thisArg */) {
              // 1. Let C be the this value.
              var C = this;

              // 2. Let items be ToObject(arrayLike).
              var items = Object(arrayLike);

              // 3. ReturnIfAbrupt(items).
              if (arrayLike == null) {
              throw new TypeError("Array.from requires an array-like object - not null or undefined");
              }

              // 4. If mapfn is undefined, then let mapping be false.
              var mapFn = arguments.length > 1 ? arguments[1] : void undefined;
              var T;
              if (typeof mapFn !== 'undefined') {
              // 5. else
              // 5. a If IsCallable(mapfn) is false, throw a TypeError exception.
              if (!isCallable(mapFn)) {
              throw new TypeError('Array.from: when provided, the second argument must be a function');
              }

              // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined.
              if (arguments.length > 2) {
              T = arguments[2];
              }
              }

              // 10. Let lenValue be Get(items, "length").
              // 11. Let len be ToLength(lenValue).
              var len = toLength(items.length);

              // 13. If IsConstructor(C) is true, then
              // 13. a. Let A be the result of calling the [[Construct]] internal method of C with an argument list containing the single item len.
              // 14. a. Else, Let A be ArrayCreate(len).
              var A = isCallable(C) ? Object(new C(len)) : new Array(len);

              // 16. Let k be 0.
              var k = 0;
              // 17. Repeat, while k < len… (also steps a - h)
              var kValue;
              while (k < len) {
              kValue = items[k];
              if (mapFn) {
              A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k);
              } else {
              A[k] = kValue;
              }
              k += 1;
              }
              // 18. Let putStatus be Put(A, "length", len, true).
              A.length = len;
              // 20. Return A.
              return A;
              };
              }());
              }






              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 23 '16 at 12:53

























              answered Apr 23 '16 at 12:42









              Ali MamedovAli Mamedov

              3,46722331




              3,46722331








              • 1





                thank you for explaining this. Could you advise, what code to use to replace my Array.from, please?

                – Robert J.
                Apr 23 '16 at 12:43













              • I have updated my answer. Just copy JavaScript code into your page. For example to the main JS file. And your problem will be solved!

                – Ali Mamedov
                Apr 23 '16 at 12:51











              • You may try myDataSet[index - 1].data = Array.prototype.slice.call(tmp);

                – Redu
                Apr 23 '16 at 12:51











              • I have tried to use your line but it did not work on my end. When using Array.From I have noticed that the function has issues when I am passing a Set to it (e.g. id does not recognize lenght of the array, mapFn is undefined, ...)

                – Robert J.
                Apr 23 '16 at 13:02











              • @Robert J. if tmp object does not have a length property first try inserting a length property to it and give it a correct value. If it doesn't work you have to make the tmp object iterable by inserting a [Symbol.iterator] method. (study this developer.mozilla.org/tr/docs/Web/JavaScript/Reference/…) once tmp is an iterable object then you can safely use myDataSet[index - 1].data = Array.prototype.slice.call(tmp); method. Could you please list the tmp object in the question.

                – Redu
                Apr 23 '16 at 13:12
















              • 1





                thank you for explaining this. Could you advise, what code to use to replace my Array.from, please?

                – Robert J.
                Apr 23 '16 at 12:43













              • I have updated my answer. Just copy JavaScript code into your page. For example to the main JS file. And your problem will be solved!

                – Ali Mamedov
                Apr 23 '16 at 12:51











              • You may try myDataSet[index - 1].data = Array.prototype.slice.call(tmp);

                – Redu
                Apr 23 '16 at 12:51











              • I have tried to use your line but it did not work on my end. When using Array.From I have noticed that the function has issues when I am passing a Set to it (e.g. id does not recognize lenght of the array, mapFn is undefined, ...)

                – Robert J.
                Apr 23 '16 at 13:02











              • @Robert J. if tmp object does not have a length property first try inserting a length property to it and give it a correct value. If it doesn't work you have to make the tmp object iterable by inserting a [Symbol.iterator] method. (study this developer.mozilla.org/tr/docs/Web/JavaScript/Reference/…) once tmp is an iterable object then you can safely use myDataSet[index - 1].data = Array.prototype.slice.call(tmp); method. Could you please list the tmp object in the question.

                – Redu
                Apr 23 '16 at 13:12










              1




              1





              thank you for explaining this. Could you advise, what code to use to replace my Array.from, please?

              – Robert J.
              Apr 23 '16 at 12:43







              thank you for explaining this. Could you advise, what code to use to replace my Array.from, please?

              – Robert J.
              Apr 23 '16 at 12:43















              I have updated my answer. Just copy JavaScript code into your page. For example to the main JS file. And your problem will be solved!

              – Ali Mamedov
              Apr 23 '16 at 12:51





              I have updated my answer. Just copy JavaScript code into your page. For example to the main JS file. And your problem will be solved!

              – Ali Mamedov
              Apr 23 '16 at 12:51













              You may try myDataSet[index - 1].data = Array.prototype.slice.call(tmp);

              – Redu
              Apr 23 '16 at 12:51





              You may try myDataSet[index - 1].data = Array.prototype.slice.call(tmp);

              – Redu
              Apr 23 '16 at 12:51













              I have tried to use your line but it did not work on my end. When using Array.From I have noticed that the function has issues when I am passing a Set to it (e.g. id does not recognize lenght of the array, mapFn is undefined, ...)

              – Robert J.
              Apr 23 '16 at 13:02





              I have tried to use your line but it did not work on my end. When using Array.From I have noticed that the function has issues when I am passing a Set to it (e.g. id does not recognize lenght of the array, mapFn is undefined, ...)

              – Robert J.
              Apr 23 '16 at 13:02













              @Robert J. if tmp object does not have a length property first try inserting a length property to it and give it a correct value. If it doesn't work you have to make the tmp object iterable by inserting a [Symbol.iterator] method. (study this developer.mozilla.org/tr/docs/Web/JavaScript/Reference/…) once tmp is an iterable object then you can safely use myDataSet[index - 1].data = Array.prototype.slice.call(tmp); method. Could you please list the tmp object in the question.

              – Redu
              Apr 23 '16 at 13:12







              @Robert J. if tmp object does not have a length property first try inserting a length property to it and give it a correct value. If it doesn't work you have to make the tmp object iterable by inserting a [Symbol.iterator] method. (study this developer.mozilla.org/tr/docs/Web/JavaScript/Reference/…) once tmp is an iterable object then you can safely use myDataSet[index - 1].data = Array.prototype.slice.call(tmp); method. Could you please list the tmp object in the question.

              – Redu
              Apr 23 '16 at 13:12















              6














              I faced the same issue. Looked at the polyfill and it is threatening huge. Here is 2 lines short solution.



              The OP basically needs to create simple array from his array-like object. I used to my taste the most efficient 2 lines plain for loop (I had to make array from HTML DOM nodelist array-like object, same applicable to JavaScript arguments object).



              For the OP's case it could sound this way:



              var temp_array = ,
              length = tmp.length;

              for (var i = 0; i < length; i++) {
              temp_array.push(tmp[i]);
              }

              // Here you get the normal array "temp_array" containing all items
              // from your `tmp` Set.


              Make it separate function and you get 3 lines universal reusable solution for the IE<9 case.



              Here is how the separate function may look like:



              /**
              * @param arr The array | array-like data structure.
              * @param callback The function to process each element in the 'arr'.
              * The callback signature and usage is assumed similar to the
              * native JS 'forEach' callback argument usage.
              */
              function customEach(arr, callback) {
              'use strict';
              var l = arr.length;
              for (var i = 0; i < l; i++) {
              callback(arr[i], i, arr);
              }
              };


              PS: here is the relevant description for forEach callback to see how to use the customEach callback.






              share|improve this answer






























                6














                I faced the same issue. Looked at the polyfill and it is threatening huge. Here is 2 lines short solution.



                The OP basically needs to create simple array from his array-like object. I used to my taste the most efficient 2 lines plain for loop (I had to make array from HTML DOM nodelist array-like object, same applicable to JavaScript arguments object).



                For the OP's case it could sound this way:



                var temp_array = ,
                length = tmp.length;

                for (var i = 0; i < length; i++) {
                temp_array.push(tmp[i]);
                }

                // Here you get the normal array "temp_array" containing all items
                // from your `tmp` Set.


                Make it separate function and you get 3 lines universal reusable solution for the IE<9 case.



                Here is how the separate function may look like:



                /**
                * @param arr The array | array-like data structure.
                * @param callback The function to process each element in the 'arr'.
                * The callback signature and usage is assumed similar to the
                * native JS 'forEach' callback argument usage.
                */
                function customEach(arr, callback) {
                'use strict';
                var l = arr.length;
                for (var i = 0; i < l; i++) {
                callback(arr[i], i, arr);
                }
                };


                PS: here is the relevant description for forEach callback to see how to use the customEach callback.






                share|improve this answer




























                  6












                  6








                  6







                  I faced the same issue. Looked at the polyfill and it is threatening huge. Here is 2 lines short solution.



                  The OP basically needs to create simple array from his array-like object. I used to my taste the most efficient 2 lines plain for loop (I had to make array from HTML DOM nodelist array-like object, same applicable to JavaScript arguments object).



                  For the OP's case it could sound this way:



                  var temp_array = ,
                  length = tmp.length;

                  for (var i = 0; i < length; i++) {
                  temp_array.push(tmp[i]);
                  }

                  // Here you get the normal array "temp_array" containing all items
                  // from your `tmp` Set.


                  Make it separate function and you get 3 lines universal reusable solution for the IE<9 case.



                  Here is how the separate function may look like:



                  /**
                  * @param arr The array | array-like data structure.
                  * @param callback The function to process each element in the 'arr'.
                  * The callback signature and usage is assumed similar to the
                  * native JS 'forEach' callback argument usage.
                  */
                  function customEach(arr, callback) {
                  'use strict';
                  var l = arr.length;
                  for (var i = 0; i < l; i++) {
                  callback(arr[i], i, arr);
                  }
                  };


                  PS: here is the relevant description for forEach callback to see how to use the customEach callback.






                  share|improve this answer















                  I faced the same issue. Looked at the polyfill and it is threatening huge. Here is 2 lines short solution.



                  The OP basically needs to create simple array from his array-like object. I used to my taste the most efficient 2 lines plain for loop (I had to make array from HTML DOM nodelist array-like object, same applicable to JavaScript arguments object).



                  For the OP's case it could sound this way:



                  var temp_array = ,
                  length = tmp.length;

                  for (var i = 0; i < length; i++) {
                  temp_array.push(tmp[i]);
                  }

                  // Here you get the normal array "temp_array" containing all items
                  // from your `tmp` Set.


                  Make it separate function and you get 3 lines universal reusable solution for the IE<9 case.



                  Here is how the separate function may look like:



                  /**
                  * @param arr The array | array-like data structure.
                  * @param callback The function to process each element in the 'arr'.
                  * The callback signature and usage is assumed similar to the
                  * native JS 'forEach' callback argument usage.
                  */
                  function customEach(arr, callback) {
                  'use strict';
                  var l = arr.length;
                  for (var i = 0; i < l; i++) {
                  callback(arr[i], i, arr);
                  }
                  };


                  PS: here is the relevant description for forEach callback to see how to use the customEach callback.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 16 '18 at 9:38

























                  answered Dec 21 '16 at 11:17









                  bob-12345bob-12345

                  184512




                  184512























                      4














                      While it's not supported on IE, you may use the polyfill from MDN.






                      share|improve this answer




























                        4














                        While it's not supported on IE, you may use the polyfill from MDN.






                        share|improve this answer


























                          4












                          4








                          4







                          While it's not supported on IE, you may use the polyfill from MDN.






                          share|improve this answer













                          While it's not supported on IE, you may use the polyfill from MDN.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Apr 23 '16 at 12:43









                          Nina ScholzNina Scholz

                          194k15107178




                          194k15107178






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f36810940%2farray-from-on-the-internet-explorer%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              Bressuire

                              Vorschmack

                              Quarantine