JSFiddle - React, Tailwind, and code Playground

by darcyclarke

JavaScript

Object.prototype.contains = function (s) { 
  return s.split('.').unshift(this).reduce((o, v) => o && o[v])
}

const a = {
	b: {
  	c: {
    	d: 'foo'
    }
  }
}

console.log(a.contains('b.c.d'))

if(a.contains('b.c.d')) {
	console.log('exists!')	
} else {
	console.log('too bad')
}