function setValue(property="",value,target={}){ const propertyArr=property.split("."); return propertyArr.reduce((pre,cur,index)=>{ if(index===propertyArr.length-1){ pre[cur]=value; return target; } pre[cur]={}; return pre[cur]; },target) } const obj={e:1}; console.log(obj,setValue('a.b.c.d.e',1,obj));