79822873

Date: 2025-11-17 23:46:23
Score: 0.5
Natty:
Report link

Not an answer to the question to get obj reference but it might be related. This is to set an object reference according to the dot notation


//# utilizing recursion, tree walk
const setDotNotationObject = (
  levels: string[],
  value,
  targetObject,
) => {
  const current = levels.shift();
  if (levels.length > 0) {
    const nested = (targetObject[current] = {});
    setDotNotationObject(levels, value, nested);
    return;
  }
  targetObject[current] = value;
};

//# usage
const targetObject = {};
setDotNotationObject(
  "a.b.c",
  'theValueToBeSet',
  targetObject,
);
Reasons:
  • Blacklisted phrase (1): Not an answer
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (0.5):
Posted by: david valentino