Flatten Nested Object

MediumRecursion + Object

Description

Given a deeply nested object, return a **flat object** where keys use dot notation to represent the path. Only flatten plain objects — arrays should remain as values.

Examples

Input: obj = { a: { b: { c: 1 }, d: 2 }, e: 3 }

Output: { "a.b.c": 1, "a.d": 2, "e": 3 }

Input: obj = { x: { y: [1, 2, 3] } }

Output: { "x.y": [1, 2, 3] }

Constraints

  • •Object nesting depth ≤ 10
  • •Keys are strings

Your Solution

JavaScript·3 test cases·Max 5,000 chars · 2s timeout · 10 runs/30s
Loading...