Thursday, December 5, 2019

the quickest way to make a copy of an array with a new pointer in JavaScript

foo = foo.slice();

 
 

This is obviously different from the way to approach an object like so:

foo = Object.assign({}, foo);

 
 

In TypeScript you would approach the object issue like so:

foo = { ...foo };

 
 

What is the difference between .splice() and .slice() in JavaScript? They both return a chunk of the array, but the slice leaves the original unedited while the splice will remove from the first array the part it hands back from its returning.

No comments:

Post a Comment