Difference in time complexity of toString and join of array

Viewed 95

Is there any difference in time complexity between [1,2,3].toString() and [1,2,3].join() . As I understand time complexity of join function is O(n) . What is the time complexity of .toString() method ?

2 Answers

Both have the same time complexity. Array.prototype.toString calls Array.prototype.join without argument. ',' is the default separator.

MDN Spec

toString() has the same time complexity of join(), the difference is that with join() is possible to choose the separator.

array.join([separator]);

Related