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
lengthproperty of the
- Then we log the
newYearsResolutionto the console.
newYearsResolutionhas two elements,
2would be logged to the console.
When we want to know how many elements are in an array, we can access the
length of the
objectives array and log it to the console.
Take this course for free