0
Hours
0
Minutes
0
Seconds

How to set value in an object by path? | Implement Lodash Set Method | JavaScript Interview Question

@Devtools Tech
129

In this question, you must create a function called set that sets the value at the path of an object.

Syntax

set(object, path, value)

Notes

  1. If a portion of the object doesn't exist, it's created.
  2. Arrays are created for missing index properties while objects are created for all other missing properties.
  3. This method mutates the original object.

Arguments

  • object (Object): The object to modify
  • path (Array|string): The path of the property to set
  • value (*): The value to set

Returns

  • object: Returns the original object

Submission

Start the timer, complete your solution, test your solution against the test cases provided by the platform, and submit it. Ideally, you should finish this question within 30-45 mins. Share your solution with us -- https://twitter.com/devtoolstech

Loading IDE...