Whenever we use String.prototype.split
with literals like so:
string.split('/')[0]
// or
string.split('/')[1]
// or
string.split('/')[2]
We benefit by limiting the search space, this allows split to exit early once it attains the number of splits and to not scan the whole string:
string.split('/', 1)[0]
// and
string.split('/', 2)[1]
// and
string.split('/', 3)[2]
// Once we get to the element we want, .split exits early (faster)
string.split('/')[0]
string.split('/').at(0)
string.split('/', 1)[0]
string.split('/', 1).at(0)
string.split('/').at(-1)
string.split('/').at(numberVar)
string.split('/')[numberVar]
specify-split-limit or prefer-split-limit
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/split#limit
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too