Set a value at a nested path in an object using dot notation.
Code
Generalconst o = structuredClone(obj);
const parts = path.split('.');
let current = o;
for (let i = 0; i < parts.length - 1; i++) {
current[parts[i]] = current[parts[i]] || {};
current = current[parts[i]];
}
current[parts[parts.length - 1]] = value;
return o;Parameters
Object to modify
Key path (dot notation)
Value to set
Browser·fetch() may be limited by CORS
More JavaScript Snippets
Count Object Properties
Count the number of enumerable properties in an object.
Deep Clone Object
Create a deep copy of an object (handles nested objects and arrays).
Deep Equal
Check if two values are deeply equal by recursively comparing all nested properties. Works with objects, arrays, and primitives.
Deep Freeze Object
Recursively freeze an object and all nested objects to make them immutable.
Deep Merge Objects
Deep merge two objects, combining nested properties.
Flatten Object
Flatten a nested object to a single level with dot notation keys.