How to solve TypeError: Cannot read properties of undefined (reading 'id')?

i have a json response like this:

[{“id":135583909,“from”:"postmaster@email.ncloud.com”,“subject”:“Verify your email address to complete your Account registration.”,“date”:“2023-01-21 21 :30:20”}]

when i sent the request, the value was successfully entered into the variable. with this test code:
response = pm. response. json()[0].id;
console. log(response);
pm. environment. set(“idemail”, response);

but when i run collection i get error like this:
TypeError: Cannot read properties of undefined (reading ‘id’)

How do I fix this, I’ve tried it but it still doesn’t work. please help me solve this.

Declare the response properly using LET, VAR or CONST.

const response = pm.response.json[0].id

Not sure how the collection run works, but if you don’t include one of those keywords, then it will create a local variable, and I’m not sure how the collection runner deals with that.

Best practice is to declare the variable type.