Implement a function to read a field inside a nested object | Frontend Problem Solving | JavaScript Interview Question
@Devtools Tech

Do you see value in our efforts?

Devtools Tech is a free platform for Frontend Engineers. It takes a lot of time, effort, and finanical resources to keep the platform running. If you see any value in our work and would like to support us then you can do using the following options.


In this question, you need to implement a function read that takes two parameters:

read(collection, property)

  1. collection: The top level parent object in which we need to find the field.
  2. property: The path of the field we need to find/read.

Expected Output: field value if field exists else undefined.

const collection = {
  a: {
    b: {
      c: {
        d: {
          e: 2

// should return 2
read(collection, 'a.b.c.d.e');

// should return undefined
read(collection, 'a.b.c.f');

Loading IDE...