Skip to content Skip to sidebar Skip to footer

Interesting Issue With Chaining Array Methods And Push

Was messing around with some array stuff earlier and discovered a very peculiar caveat consider this code: [1,2,3].map(function(el) { return el * 2}).push(4*2).join(' '); In writi

Solution 1:

Why is the length property being returned here?

It is defined in the specification:

The arguments are appended to the end of the array, in the order in which they appear. The new length of the array is returned as the result of the call.

 

Why is breaking as is?

Well, you answered this already yourself: .push returns the new length and .join is not defined for numbers.


Post a Comment for "Interesting Issue With Chaining Array Methods And Push"