JSFiddle - React, Tailwind, and code Playground

JavaScript

function nest(obj, props) {

  if (props.length === 0) {
    return obj;
  }

  obj[props[0]] = {};
  return nest(obj[props[0]], props.slice(1));
}

const a = {}
console.log(nest(a, ['b', 'c', 'x', 'y', 'z']));
console.log(a);

//log:
// {}
// {b:{c:{x:{y:{z:{}}}}}}

function append(txt, appendArr) {

  if (appendArr.length === 0) {
    return txt;
  }

  return append(txt + appendArr[0], appendArr.slice(1));
}

let text = "text"
console.log(append(text, ['b', 'c', 'x', 'y', 'z']));
console.log(text);

// log:
// textbcxyz
// text