How to set value in an object by path? | Implement Lodash Set Method | JavaScript Interview Question
@Devtools Tech
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
- If a portion of the object doesn't exist, it's created.
- Arrays are created for missing index properties while objects are created for all other missing properties.
- This method mutates the original object.
Arguments
object (Object)
: The object to modifypath (Array|string)
: The path of the property to setvalue (*)
: 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