Logos DX
    Preparing search index...

    Function setDeep

    • Sets a value deep within a nested object using dot notation path.

      Creates intermediate objects if they don't exist along the path. Mutates the original object in place. Use this when you need to update nested configuration objects, set metrics in nested structures, or build objects incrementally without manual property checking at each level.

      Type Parameters

      • T extends object
      • P extends string

      Parameters

      • obj: T

        object to modify

      • path: P

        dot-separated path to the target property

      • value: PathValue<T, P>

        value to set at the path

      Returns void

      const metrics = { memory: { heap: 100 } };
      setDeep(metrics, 'memory.rss', 1024);
      // metrics is now { memory: { heap: 100, rss: 1024 } }
      // Creates missing intermediate objects
      const config = {};
      setDeep(config, 'server.port', 3000);
      setDeep(config, 'server.host', 'localhost');
      setDeep(config, 'database.connection.timeout', 5000);
      // config is now { server: { port: 3000, host: 'localhost' }, database: { connection: { timeout: 5000 } } }
      // Building response objects incrementally
      function buildResponse(data: any) {

      const response = {};

      setDeep(response, 'status.code', 200);
      setDeep(response, 'status.message', 'OK');
      setDeep(response, 'data.results', data);

      return response;
      }