How to set value of multidimential object when name path is stored in array of unknown length?

I have an array of unknown length which defines the path to content I want to alter in a object.

This is what I want.

let updatedContent = "Hello World!";
let myArray = ["layer1","layer2","layer3"];
myObject["layer1"]["layer2"]["layer3"] = updatedContent;

My problem is myArray is of unknown length. What is the best way to update a value in the object?