1const getCircularReplacer = () => {
2 const seen = new WeakSet();
3 return (key, value) => {
4 if (typeof value === "object" && value !== null) {
5 if (seen.has(value)) {
6 return;
7 }
8 seen.add(value);
9 }
10 return value;
11 };
12};
13
14JSON.stringify(circularReference, getCircularReplacer());
15