It's incredible how much difference sharing the error message can make, isn't it? Always remember to provide that crucial information next time.
If you're encountering issues with optional chaining "?." in your code, it may be due to using an outdated version of Node.js or a Browser that does not support this feature.
As per node.green, Node.js began supporting optional chaining from version 14.5.0 onwards. However, according to canIUse, Internet Explorer lacks support for optional chaining entirely, while other major browsers have adopted it since early 2020.
If you find yourself facing this issue, consider updating your environment to a compatible version. If that's not possible, utilizing a transpiler like Babel can help by converting your code to an older JavaScript version.
Prior answer:
The error message you mentioned seems to be:
Uncaught TypeError: Cannot read properties of undefined (reading '0')
You might have forgotten to use optional chaining when accessing the data array. Consider using data?.[0]
to prevent such errors.
In cases where your response is structured like res = { payload: {} }
, ensure to include expressions like
res?.payload?.data?.[0]?.tnxResponse
to avoid the issue of accessing properties on "undefined", which results in generating errors.