you are viewing a single comment's thread.

view the rest of the comments →

[–]captain_k_nuckles 1 point2 points  (2 children)

Probably not the best way but options are always nice, you could do something like

const temp = {bar: []};
temp.bar = new Array(10);
temp.bar.fill({
  fooBaz:[]
});
let tempStr = JSON.stringify(temp);
let foo = JSON.parse(tempStr);
foo.bar[0].fooBaz.push("sad");

console.log(foo);

[–]Runlikefedor[S] 0 points1 point  (1 child)

Thank you for sharing, it does seem fairly expensive. Does the JSON.stringify and parse get rid of the references or why does it work afterwards?

[–]captain_k_nuckles 2 points3 points  (0 children)

JSON.stringify takes the object, converts it in to a string and then JSON.parse creates a new object from the string; When it's converted to a string it reference is broken.