The .length property

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 the newYearsResolutions array.
  • Then we log the length of newYearsResolution to the console.
  • Since newYearsResolution has two elements, so 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.



Find the length of the objectives array and log it to the console.

Folder Icon

Take this course for free

Already have an account?