Loading ...
Sorry, an error occurred while loading the content.

1470Re: slice method appears slower in loops than incrementally listing array indexes

Expand Messages
  • sandyhead25
    Sep 5, 2010

      String replace would certainly be faster, because such instructions pass to the same code base on which the JavaScript interpreter sits. String replace does not provide an index for its global matches so as to allow multiple instructions to execute on each match or pull each match into an empty array. In not for such conditions I would certainly use the replace method.

      It should be noted that while it is possible to pass a function with arguments into the replace method one should never do so. This essentially creates a whole through the interpreter to the underling code base. That means that if you can inject code into one of the function arguments you can pass that code through the JavaScript interpreter to possibly compromise the executing software. I would gladly sacrifice a measurable amount of performance as a general best practice to prevent potential code injection.


    • Show all 5 messages in this topic