Using slice () with or without [end]

Is there any performance difference with the slice () method with or without the last argument [end]?

Example:

var m = ['But', 'Will', 'It', 'Blend', 'Question'];
var r = m.slice(1,3);

OR

var r = m.slice(2);

PS: not the result, as it is, but a performance problem.

+4
source share
2 answers

If you look at the implementation https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/slice , you will see that if the second argument is not sent, it uses the length of the array so no, I I think they are the same.

Array.prototype.slice = function(begin, end) {
  // IE < 9 gets unhappy with an undefined end argument
  end = (typeof end !== 'undefined') ? end : this.length;
  .....................................
});
+4
source

(O(n)) , . , .

-, , ( ) (#length). , #slice(4) #slice(4, #length), .

, AST , , . , . script .

, . .

+1

All Articles