-
Here’s the MDN documentation link: Issue with serializing circular references When we have an array with circular references, and pass it to const arr = [];
arr.self = arr;
try {
JSON.stringify(arr);
} catch (error) {
console.error("Failed to stringify arr:", error);
} The code above runs sucessfully without throwing any errors or exceptions. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
When serializing an array, properties on the array are ignored, so in your case the empty array is serialized as |
Beta Was this translation helpful? Give feedback.
When serializing an array, properties on the array are ignored, so in your case the empty array is serialized as
[]
, so the self-reference causes no issues, see: https://developer.mozilla.org/en-US/play?id=vSKVZUPzRAXKbEAHdrKm1tRhxnGvKg9CFup9xvCCdz3%2BNRh8QLmsooBoxHvEAYRGlaFWGp3Xkq0U3QRO