In my React app, at one point I'm trying to copy a Map from an object, but it's not working for me.
The initial user object has the structure:
user: { videoTracks: Map, ... other fields... }
If I do a console log on user, I get this for videoTracks:
Then I do this: const newVideoTracks = user.videoTracks;
and I would expect newVideoTracks to be the same as the first image, but instead I get the following:
It has 2 entries and size:2, but it says Map(1) at the top.
I know the console isn't always accurate, but in this case when I subsequently use newVideoTracks, it behaves as though there is only 1 entry.
I assume I need to do some cloning rather than just copying it, so I tried both of the following:
const newVideoTracks = new Map(user.videoTracks);
- this didn't make any difference
const newVideoTracks = Object.assign({}, user.videoTracks)
- caused a crash
What's the correct way to do this?