0

I am trying to check if the key exists in the nesting level to avoid the error data={ payment-term:{ description:xyz description } }

how I am fetching data[payment-term].description It works well with the above set of data but gets error on the below set of data data={ payment-term: null }

so in order to avoid the error, I am using optional chaining but am not able to write due to I have a special character in the key

let description= data?[payment-term]?.description getting error on the above statement Can anybody help me to write the statement in the correct way?

MNSH
  • 55
  • 1
  • 8
  • 3
    `let description= data?.['payment-term']`. Reading [the documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining#syntax) is always useful. – Teemu Sep 02 '22 at 07:10

0 Answers0