To find the length of an array in JavaScript, use the .length property. This property returns the number of elements in the array. Here’s an example:
const array = [1, 2, 3, 4, 5];
console.log(array.length); // Output: 5
The .length property is dynamic, meaning it updates automatically when elements are added or removed from the array. For instance:
array.push(6); // Add an element
console.log(array.length); // Output: 6
array.pop(); // Remove an element
console.log(array.length); // Output: 5
This method is simple, efficient, and widely used for determining array size.