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:
lengthproperty of the
newYearsResolutionto the console.
newYearsResolutionhas two elements, so
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.