📜  json stringify close circle - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:40.349000             🧑  作者: Mango

代码示例1
const getCircularReplacer = () => {
  const seen = new WeakSet();
  return (key, value) => {
    if (typeof value === "object" && value !== null) {
      if (seen.has(value)) {
        return;
      }
      seen.add(value);
    }
    return value;
  };
};

JSON.stringify(circularReference, getCircularReplacer());