How to get the length (number of properties) of an object in JavaScript?
Hello everyone! I just started learning JavaScript and ran into a problem. Arrays have a `length` property that shows the number of elements. But when I try to do the same with an object, I get `undefined`.
Here's an example:
```javascript
let user = {
name: 'Ivan',
age: 30,
city: 'Moscow'
};
console.log(user.length); // undefined
```
I expected to see `3`, since the object has three properties. But instead, I got `undefined`. Why is that? And how do I correctly count the number of properties in an object?
I know that objects are not arrays, but I need to dynamically check how many fields an object contains, for example, after adding or removing properties. Iterating over each property manually is inconvenient, especially if the object is large.
Please tell me, is there a built-in