dynamically generated deep objects

I want to ask for help with the problem. I have an existing deep Javascript object from which I want to dynamically generate multiple versions. I have a method that has 2 parameters. first: the object from which I want to generate new ones, second: a number or an array of numbers

for example:

let myObj = {

  brown: {
    50: '#f9f8f2',
    100: '#f3f0e6',
  },
  singleProp: '#e6b01e',
  propLvl1: {
    color: '#32a852',
    sub1: {
      color: '#44eff2',
      sub2: {
        color: '#f2448d'
      },
    },
  },
};

myFunction(myObject, [10, 30]);

my goal would be:

  MY-10-brown: {
    50: '#(DYNAMICVALUE)f9f8f2',
    100: '#(DYNAMICVALUE)f3f0e6',
  },
  MY-10-singleProp: '#(DYNAMICVALUE)e6b01e',
  MY-10-propLvl1: {
    color: '#(DYNAMICVALUE)32a852',
    sub1: {
      color: '#(DYNAMICVALUE)44eff2',
      sub2: {
        color: '#(DYNAMICVALUE)f2448d'
      },
    },
  }

  MY-30-brown: {
    50: '#(DYNAMICVALUE)f9f8f2',
    100: '#(DYNAMICVALUE)f3f0e6',
  },
  MY-30-singleProp: '#(DYNAMICVALUE)e6b01e',
  MY-30-propLvl1: {
    color: '#(DYNAMICVALUE)32a852',
    sub1: {
      color: '#(DYNAMICVALUE)44eff2',
      sub2: {
        color: '#(DYNAMICVALUE)f2448d'
      },
    },
  }

So far I have reached him:

export default function generateObjects(obj, numbers) {
  let newObj = {};

  for (let q = 0; q < transparentValue.length; q += 1) {

    let Obj = doTheJob(obj, transparentValue[q]);
    Object.assign(newObj, Obj);
  }
  return newObj;
}

function doTheJob(obj, number) {

  const newObj = {};
  let newKey = '';

  Object.keys(obj).forEach(function (key) {

    let trim = `${obj[key]}`.substring(1);
    let newValue = `#${anotherObject[number]}${trim}`;

    if (typeof obj[key] === 'object') {
      newKey = `MY-${number}-${key}`;
      newObj[newKey] = obj[key];
      generateNewObj(newObj[newKey], number);
      return;
    }
    if (typeof obj[key] === 'string') {
      newObj[key] = newValue;
    }
  });

  return newObj;
}

Answer

You could create new properties for the first level of the object and take copies of data.

const
    copy = value => typeof value === 'object'
        ? Object.fromEntries(Object.entries(value).map(([k, v]) => [k, copy(v)]))
        : typeof value === 'string'
            ? value.replace('#', '#DYNAMICVALUE')
            : value
    create = (object, values, header) => Object.fromEntries(Object
        .entries(object)
        .reduce((r, [k, v]) => [...r, ...values.map(i => [[header, i, k].join('-'), copy(v)])], [])
    ),
    myObj = { brown: { 50: '#f9f8f2', 100: '#f3f0e6' }, singleProp: '#e6b01e', propLvl1: { color: '#32a852', sub1: { color: '#44eff2', sub2: { color: '#f2448d' } } } };

console.log(create(myObj, [10, 30], 'my'));
.as-console-wrapper { max-height: 100% !important; top: 0; }