Learn
One of an array’s built-in properties is length
and it returns the number of items in the array. We access the .length
property just like we do with strings. Check the example below:
const newYearsResolutions = ['Keep a journal', 'Take a falconry class']; console.log(newYearsResolutions.length); // Output: 2
In the example above, we log newYearsResolutions.length
to the console using the following steps:
- We use dot notation, chaining a period with the property name to the array, to access the
length
property of thenewYearsResolutions
array. - Then we log the
length
ofnewYearsResolution
to the console. - Since
newYearsResolution
has two elements,2
would be logged to the console.
When we want to know how many elements are in an array, we can access the .length
property.
Instructions
1.
Find the length
of the objectives
array and log it to the console.
Take this course for free
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.