3

I haven't used Sets very much, even though I'm familiar with Object/Array references and the need for shallow copies:

const originalObject = { foo: 'bar' };
const clonedObject1 = Object.assign({}, originalObject);
const clonedObject2 = { ...originalObject };

const originalArray = ['bar'];
const clonedArray1 = originalArray.slice();
const clonedArray2 = [ ...originalArray ];

I'm using React and need a new Set() to setState without mutating and re-using the same reference.

How can I perform a shallow copy or slice a new Set()?

neaumusic
  • 10,027
  • 9
  • 55
  • 83

0 Answers0