JSFiddle - React, Tailwind, and code Playground

by evgkch

JavaScript

const Safe = {

  get: (target, [firstProp, ...restProps] = []) =>
    !!target
      ? firstProp
        ? target[firstProp]
        		? Safe.get(target[firstProp], restProps)
            : target[firstProp]
        : target
      : target,
};

console.log(Safe.get({ a: { b: 1 }}, ['a', 'b', 'c']))