Determining Array Length

Sometimes we do not know how many elements an array has (perhaps the array was created by someone else, or the number of elements in the array changes) and we need to find out.

To do this, we use the length property, which returns the number of elements in the array. The length property is used by appending .length to the value whose length we want to determine. Let's look at an example:

const students = ["Jennifer", "Boris", "Nancy", "David", "Ava"];

If we want to find out how many students are in the students array, we can store the number of elements in a variable and print it:

const numberOfStudents = students.length;
console.log(numberOfStudents);  // Prints: 5

Or print it directly:

console.log(students.length); // Prints: 5

Instructions

Using the .length property, print the number of elements in the coworkers array.

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with:

5/10

Determining Array Length | Start Coder