setValue
@tsed/core
Usage
typescript
import { setValue } from "@tsed/core";Overview
ts
function setValue(scope: any, expression: string, value: any, separator?: string): void;scope (
any): - The target object or Map to set the value onexpression (
string): - Dot-notation path to the property (e.g., "user.profile.name")value (
any): - The value to set at the specified pathseparator (
string): Optional. - Path separator character (default: ".")
Description
Sets a value on an object using a dot-notation expression path.
Supports both plain objects and Map-like objects (with .set(), .get(), .has() methods). Automatically creates intermediate objects as needed. Protected keys (__proto__, constructor, prototype) are ignored for security.
typescript
const obj = {};
setValue(obj, "user.name", "John");
// obj is now { user: { name: "John" } }