What is the use of Array.length in JavaScript?
a) To find the number of elements in an array
b) To remove elements from an array
c) To sort elements in an array
d) To add elements to an array
Answer:
a) To find the number of elements in an array
Explanation:
The Array.length
property returns the number of elements in an array. It is useful for determining the size of the array or for iterating over array elements.
Example:
var fruits = ["Apple", "Banana", "Cherry"];
console.log(fruits.length); // Output: 3