Almost all of these I use pretty regularly and feel like every modern codebase should use them. Here are some additional shorthands I use:
Range 1,2,3...n:
[...Array(n).keys()]
Remove key from object:
const { key: _, obj } = object;
Swap array items:
[arr[x], arr[y]] = [arr[y], arr[x]]
Thank you for sharing this. I'm saving this comment for future reference
Gives you a range 0 to n-1. For a range 1 to n, you could use:
0
n-1
1
n
// This (much faster)... Array.from({length:n},(_,i)=>i+1) // Or maybe this (shorter but slower)... [...Array(n).keys()].map(i=>i+1)
Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment's permalink.
Hide child comments as well
Confirm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Almost all of these I use pretty regularly and feel like every modern codebase should use them.
Here are some additional shorthands I use:
Range 1,2,3...n:
Remove key from object:
Swap array items:
Thank you for sharing this. I'm saving this comment for future reference
Gives you a range
0
ton-1
. For a range1
ton
, you could use: