Dawid Janiga’s Post

I recently stumbled upon a neat JavaScript method: Array.with(). It creates a new array with one item replaced. Shorter to write, but more importantly - easier to understand. Its design clearly communicates what will happen, not how it’s implemented. That’s a big difference compared to manual array copying with the spread operator. Nice. Simple. Useful. I came across it while Cursor was suggesting a cleaner way to write a reducer. ---- Link to a short blog post is in the comments, if you’d like to bookmark it. #javascript #TIL #frontend #backend #svelte #react #node

  • Before and After example of JS Array.with()

Array.with() is clean and expressive for immutable index replacement, especially in reducers. That said, it’s a niche improvement, not a new default. Use it where intent is obvious, ensure runtime support, and don’t replace well understood spread patterns just for novelty. Good post and happy new year 🎉 😊

Like
Reply
See more comments

To view or add a comment, sign in

Explore content categories