Home > Enterprise >  Node.js showing TypeError: Cannot read properties of undefined
Node.js showing TypeError: Cannot read properties of undefined

Time:11-19

RV =(typeof (myresult.CDF.UTILITYTYPE.D2.INSTPARAM[0].VALUE !== 'undefined')) ? myresult.CDF.UTILITYTYPE.D2.INSTPARAM[0].VALUE : 'NA';
                                                             

in the above code i want to get the value , if the key does not exists it should take 'NA' but iam getting below error

Error: - TypeError: Cannot read properties of undefined (reading 'INSTPARAM')

CodePudding user response:

myresult.CDF.UTILITYTYPE.D2?.INSTPARAM[0].VALUE ?? 'NA';

using the option chaining.

  • Related