Table of Contents
- Other Related Concepts
X.length //returns the length of X
Here X can be either a string or an array.
const xyz = "Hello World!"; console.log(xyz.length); // Output: 12
const xyz = ['bat', 'ball', 'mat', 'pad']; console.log(xyz.length); // Output: 4
Note: While dealing with the length function remember that the length of an object is always greater than the index of it’s last element.