can't read property of undefined
时间: 2023-09-24 09:05:38 浏览: 33
This error message typically occurs when you're trying to access a property or method of an object that doesn't exist or is undefined.
Here's an example:
```
let person = {
name: "John",
age: 30
}
console.log(person.address.street); // This will throw an error because "address" is undefined.
```
To fix this error, you need to make sure that the object and its properties exist before accessing them. Here's one way to do it:
```
let person = {
name: "John",
age: 30
}
if (person.address && person.address.street) {
console.log(person.address.street);
} else {
console.log("Address is undefined or doesn't have a street property.");
}
```
In this case, we're checking if `person.address` exists and if it has a `street` property before logging it to the console. If either of those conditions is false, we log an error message instead.