r/learnjavascript • u/RobGoLaing • Sep 02 '26
I've become a big fan of splice
As part of my project to write notes of what I learn practicing contemporary browser JavaScript by creating webapp games, I've written some notes and examples on Array Literals.
This was inspired by creating a "hardware-agnostic, framework-free" webapp solitaire card game, Loot the Loop (a game designed by Wil Su, part of what's made this project fun is that besides learning contemporary JavaScript, I've discovered lots about contemporary solitaire card game design).
TL:DR — In the past I've tended to use shift, unshift, pop, push... which are ok, but concat is an antipatern. Just learning splice does all the above while making arrays much simpler.
3
u/everdimension Sep 02 '26
Nothing like having a mutating "upsert" helper combined with immer
Btw, how is "concat" an "antipattern"?!
1
u/chikamakaleyley helpful Sep 02 '26 edited Sep 02 '26
mmmm if you plan to change your approach and always use
.splice()in place of those other methods, or if you plan to refactor some code and replace everything with.splice()- you will overcomplicate your codeaka, off the top of my head if you were to console.log
vs
Both would have the same output. One of them took you slightly longer to figure out.
1
u/[deleted] Sep 02 '26
[removed] — view removed comment