interesting issue with chaining array methods and push

后端 未结 1 1309
旧巷少年郎
旧巷少年郎 2021-01-22 01:54

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

1条回答
  •  清酒与你
    2021-01-22 02:22

    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.

    0 讨论(0)
提交回复
热议问题