Why does array.concat copy the array rather than doing for(e...) array.push(e);

That’s how it’s defined in the ECMAScript standard for ages, so both flash and js implemented it that way. And FWIW even PHP does it that way: http://php.net/manual/en/function.array-merge.php

So it’s not really a design choice. That said, you can just make a static extension:

class ArrayTools {
  static public function append<T>(target:Array<T>, toBeAdded:Array<T>) {
    for (x in toBeAdded) target.push(x);
    return target;
  }
}

Then add using ArrayTools; to a toplevel import.hx and you’re all set :wink:

4 Likes