Copying JavaScript object and arrays
I recently learned this method:
Copying a JavaScript Object
const source = { a: 1, b: 2 };
const copy = Object.assign({}, source);
Copying a JavaScript Array
const arr = [0,2,3,4,5];
const arrCopy = arr.slice(0);
These two functions come handy when y...
rmoran86.hashnode.dev1 min read
Chris Bongers
Looking to get into development? As a full-stack developer I guide you on this journey and give you bite sized tips every single day 👊
You can also use the three dot method
const arr = [0,2,3,4,5]; const arrCopy2 = [...arr]; console.log(arrCopy2);