0

Is there a way to get rid of this type of checks for objects:

reader && reader.firstProp && readerSecondProp && readerThirdProp && doSomething

Object looks like this:

const reader = {firstProp :{readerSecondProp:{readerThirdProp: 'yeeee'}}}

or

const reader = {}

I want to somewthing like this

proporyExist(readerThirdProp) && do something
ZiiMakc
  • 31,187
  • 24
  • 65
  • 105
  • 1
    [Accessing nested JavaScript objects with string key](https://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key) – Andreas Feb 25 '19 at 15:36
  • i need simple check, without much of code. – ZiiMakc Feb 25 '19 at 15:37
  • 1
    You can you some external libraries if you don't want to write your own implementation. get from lodash will serve your purpose here. https://lodash.com/docs/4.17.11#get – Sunil Chaudhary Feb 25 '19 at 15:40

0 Answers0