Skip to main content
100%

mapValuesDeep with circular references detection

✓ Published0🌍 Public
RRestuta
Last edited Aug 30, 2017
Created on Aug 30, 2017

This example demonstrates a recursive utility that applies a mapping function to every non-object value in a nested data structure, while preserving circular references instead of falling into infinite recursion. The code uses lodash’s `_.mapValues` and `_.isPlainObject` to traverse plain objects, and a JavaScript `Set` to track already-visited objects. When a circular reference is detected, the original value is returned unchanged rather than being re-processed. This approach is useful for safely transforming deep, potentially cyclic JSON-like data without stack overflows.

AI-generated description

Similar vizzes