Wednesday, May 12, 2021

simplest deep array copy in javascript

Whenever I go a while without a blog update, I think of the character "Jim Anchower" on the Onion, with editorials that usually started "Hola, amigos. I know it's been a long time since I rapped at ya".

But, you know. I moved last month, and work has been very good but more about building with tech we established in previous sprints than learning new stuff I wanted to share and record...

Anyway, I had to look up how to clone arrays in javascript... most of them are only shallow copies, bad for two dimensional stuff, but this trick works a treat:

const copiedArray = JSON.parse(JSON.stringify(originalArray));


No comments:

Post a Comment