Given that an object and a string of data paths are known, how to find the value according to the data path

there is an object

var obj = {
  a: {
    b: {
      c: 3
    }
  }
};
var text = "a.b.c"

how to modify the value of c according to text path to 4 , so that the result is

{
  a: {
    b: {
      c: 4
    }
  }
}

Mini Program"s setData method supports data path input. I just want to know how to implement this function. The known idea is recursion

.
let text = "a.b.c";
this.setData({
    [text]: 4
})

Thank you for your help

Mar.11,2021

var obj = {
  a: {
    b: {
      c: 3
    }
  }
}
var text = 'a.b.c'
function setData(obj, config) {
  let keys = Object.keys(config)
  keys.forEach(key => {
    cur = obj
    let names = key.split('.')
    let last = names.length - 1
    names.forEach((name, index) => {
      if (!cur[name]) cur[name] = {}
      if (last === index) {
        cur[name] = config[key]
      } else {
        cur = cur[name]
      }
    })
  })
}
setData(obj, {[text]: 4, 'e.f': 6}) // obj: {a:{b:{c:4}},e:{f:6}}}

function setObjText(o,t,v){ //
let tmp=o;
let t2k=t.split('.');
for(let i=0;i<t2k.length;iPP){
    tmp[t2k[i]]=typeof(tmp[t2k[i]])=='object'?tmp[t2k[i]]:{} ;
    tmp=tmp[t2k[i]];
  }
  tmp=value;
}
Menu