I have found a way to copy the entries from one Map to another Map where the target Map has multiple reference variables but I suspect it is not optimal. Is there a shorter/more efficient way?
const mapFrom = new Map([[1, 'from']]); const mapTo = new Map([[1, 'to']]); const refMapTo = mapTo; mapTo.clear(); for (const [key, value] of mapFrom) mapTo.set(key, value); if (mapTo.get(1) === mapFrom.get(1) && mapTo === refMapTo) { console.log('this code works but can I avoid the `for...of` iteration?'); }
for-of?copy(at later stage) without looping through the values. EithermapTomust be a reference tomapFromfrom the beginning or you need to have this loop one way or another