question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: `Array#push` + rest parameter instead of `Array#concat`

See original GitHub issue

Just a minor suggestion, not sure if it’s actually any better or preferred. Maybe:

Fail

array = array.concat(otherArray);

Pass

array.push(...otherArray);

Real-life example https://github.com/xojs/xo/pull/538/commits/31068d46f40e77302921dfad8b218426a3ebefec

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
fregantecommented, Nov 2, 2021

I’ve heard that JavaScript can pass at most 30 thousand arguments to a function

Could this be part of the error message, without an autofix?

Prefer array.push to .concat if the array is smaller than 5000 items // for safety
Read more comments on GitHub >

github_iconTop Results From Across the Web

Why use `concat` instead of `push` in this instance?
If some other code has a reference to the existing array in actionQueue , using concat will not affect that.
Read more >
Javascript Array.push is 945x faster than Array.concat - DEV ...
Javascript Array.push is 945x faster than Array.concat ... fastest method to merge arrays is to use .push which accepts n arguments:.
Read more >
airbnb/javascript: JavaScript Style Guide - GitHub
Use the object rest parameter syntax to get a new object with certain ... 4.2 Use Array#push instead of direct assignment to add...
Read more >
JavaScript Tutorial: The Basics
ECMAScript 2018 (ES9): Added rest parameters ( ... ), spread operator, asynchronous iteration, additions to regular expression.
Read more >
eslint-config-ariporad - npm
`let` is block-scoped rather than function-scoped like `var`. ... Plus, rest arguments are a real Array, and not merely Array-like like ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found