#

Sunny Kushwaha

Admin

Angular object length Hack

Here's an example of how to get object length: To calculate the length of an object, you can use the Object.keys() method, and then use the length property of that array to get the number of keys. "Object.keys()" method returns Array of keys.

object-length.component.ts
                                    

                                        myObj: Object = {
                                            name: 'John',
                                            age: 30,
                                            city: 'New York'
                                          };
                                          
                                        objLength: any = Object.keys(myObj).length;
                                          
                                        console.log(objLength); // Output: 3

                                    
                                

In this example, myObj is an object with three key-value pairs. We use the Object.keys() method to get an array of keys in the object, and then get the length of this array using the length property. The output is 3, which is the number of keys in the object.

That's all you need to get object length my friend!