I have an object, where in some requests it returns without certain values.
The problem, when trying to validate the values, it generates error:
Note:Whenanalyzing,Inoticedthefollowingsituation:
Code:
vara={f:1}console.log(a)//{f:"Olha"}
console.log(a.b) //undefined
console.log(a.b.c) //Uncaught TypeError: Cannot read property 'c' of undefined at window.onload
The big problem is whether the previous value has not been set. Because it is a third-party API, I do not know which values can be set.
How do I validate in this type of situation?
Jsfiddle: