Hi there,
is there a better way to check whether the value is NULL or empty?
I am getting errors when I receive a null value
Thank you in advance.
Hi there,
is there a better way to check whether the value is NULL or empty?
I am getting errors when I receive a null value
Thank you in advance.
Hey @tuliovargas,
Welcome to the community
Can you please share what exactly you’re trying to do? Also, if you can share the error you get, it will be helpful to debug
hi @harshil1712 , thank you for your prompt answer.
Sometimes I get the filed
items[0].json.result.ADDRESS_POSTAL_CODE
with value inside like “1234”, however sometimes the API sends this field NULL, then I’d like to check before if this field is populated or not.
Can you share what value does the API return? Does it return NULL
or it doesn’t return that particular field?
To avoid the error you can try using optional chaining.
In your example it would be items[0].json.result?.ADDRESS_POSTAL_CODE
.
Here’s an example
x = {test: 1}
x.nonexistent.test
/* VM527:1 Uncaught TypeError: Cannot read properties of undefined (reading 'test')
at <anonymous>:1:15
(anonymous) @ VM527:1*/
// Using optional chaining
x.nonexistent?.test
// undefined