0
Hours
0
Minutes
0
Seconds
You need Login/Signup to run/submit the code.

Implement a function to read a field inside a nested object | AWS Frontend Interview Question | JavaScript Interview Question

@Devtools Tech
330

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...