Frontend101 logoFrontend101
← Problems
#14MediumJavaScript functions

14. Flatten Nested Object

JavaScript

Implement flattenObject(obj) to flatten deeply nested objects into a single-level object with dot-separated keys.

Example 1:
flattenObject({ a: { b: { c: 1 } }, d: 2 });
// { "a.b.c": 1, d: 2 }
solution.js
Flattens nested objects with dot notation
expect(flattenObject({ a: { b: { c: 1 } }, d: 2 })).toEqual({ "a.b.c": 1, d: 2 })