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
In this question, you need to implement a function read
that takes two parameters:
read(collection, property)
collection
: The top level parent object in which we need to find the field.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');