3 Replies Latest reply on Jan 1, 2016 6:05 AM by Jump_Over

    Is there a better way of performing array functions on a collection

    McShaman Level 1

      Collections... While having their advantages are a little bit painful as well. Want to pollyfill a lot of modern Javascript functions such as Array.forEach and Array.reduce but as I understand collections are not Arrays so pollyfilling the prototype is not going to help me too much.

       

      I wrote a little function that converts a collection to an array:

       

      /**
       * Converts Adobe collection objects to JavaScript arrays
       *
       * @version 1.0.0
       */
      function collectionToArray(col) {
      
        'use strict';
      
        var array = [];
      
        Array.prototype.forEach.call(col, function(itm) {
      
        array.push(itm);
      
        });
      
        return array;
      
      }
      

       

      It works... It returns an array that I can perform native Javascript functions on. I just wanted to check with the community if this went against what is considered best practices for Adobe scripting.