What is the use of Array.length in JavaScript?

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
    

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top