Skip to content

Add note about function call args limit for using spread syntax to concatenate arrays#43838

Open
solsword wants to merge 2 commits intomdn:mainfrom
solsword:main
Open

Add note about function call args limit for using spread syntax to concatenate arrays#43838
solsword wants to merge 2 commits intomdn:mainfrom
solsword:main

Conversation

@solsword
Copy link
Copy Markdown

Description

The Array.push documentation gives an example of using spread syntax to concatenate arrays. However, it doesn't mention the limitation which applies in this case: the array being concatenated needs to be short enough that it doesn't go beyond the limit on the number of arguments to a function call. This adds a note about that to the section with that example, and suggests using Array.concat instead in that case (Array.concat was already linked there as an alternative). It also mentions that Array.concat makes a copy so people who don't follow the link will get a hint about how Array.concat is different from Array.push(...).

Motivation

It's easy in testing to see that Array.push(...x) works if you're testing with a small array x, including in unit tests you might set up. However, in production when x grows larger than the limits on function call parameters (which is pretty easy) this will break. So this is a hidden sharp edge to the suggested concatenation method in the docs. Since Array.concat always makes a copy which is not always desirable due to time/memory overhead, there's an extra incentive to use the push(...) method (and the existing docs don't highlight this distinction on the Array.push side). Adding a note will hopefully help some people avoid a headache.

…in call arguments limit

Array.push mentions using spread syntax to effectively concatenate arrays, but does not note the key limitation that this only works if the array being concatenated has fewer elements than the limit on function call arguments. I've added a note about that to the relevant section.
Update Array.push to note limitation of spread syntax based on functo…
@solsword solsword requested a review from a team as a code owner April 17, 2026 10:10
@solsword solsword requested review from wbamberg and removed request for a team April 17, 2026 10:10
@github-actions github-actions Bot added Content:JS JavaScript docs size/xs [PR only] 0-5 LoC changed labels Apr 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:JS JavaScript docs size/xs [PR only] 0-5 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants