'deep cloning a typed array in Javascript
Trying to deep clone an array buffer (i.e, pass by value not by reference)
const deepClone = (buf) => {
uint32 = new Uint32Array(buf);
let newBuf = new ArrayBuffer(buf.byteLength);
let uint32new = new Uint32Array(newBuf);
// This works fine
uint32.forEach((el, i) => {
uint32new[i] = el;
});
// but this doesn't
uint32new = uint32.map((el) => {return el});
// neither does this
uint32new = [...uint32];
return newBuf;
};
The latter 2 merely return an empty (0's) buffer
why?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
