JSFiddle - React, Tailwind, and code Playground

JavaScript

const a = {
 b: {
  c: 2
 }

};
const b = {
 b: {
  c: {
    d: 3
  }
 }

};

function getValue(obj, props = []) {
  if (props.length === 0) {
    return obj;
  } else {
    return getValue(obj[props[0]],  props.slice(1));
  }
  
  
}

console.log(getValue(a, ['b', 'c']));
console.log(getValue(b, ['b', 'c', 'd']));