Deviopath › JavaScript

Get Value by Path

Hard · Parsing

Write a function getByPath that reads a nested value from obj using a path string like "a.b[0].c".

- Property names are separated by dots.

- Array indexes are written in square brackets and can be chained, like "m[1][0]".

- If any step along the way does not exist (or you reach null or a non-object too early), return undefined.

- An empty path returns obj itself.

Next: Deep Equal