JavaScript Array Mastery
    • Overview
    • What is an Array?
    • Array Indexing
    • Mutable vs. Immutable
    • Length Property
    • Sparse Arrays
    • Array vs. Object
    • Accessor Methods

      at
    • concat
    • includes
    • indexOf
    • join
    • lastIndexOf
    • slice
    • Array Creation

      Array.from
    • Array.of
    • new Array()
    • Iteration Methods

      entries
    • keys
    • values
    • Mutating Methods

      Mutating array methods
    • copyWithin
    • fill
    • pop
    • push
    • reverse
    • shift
    • sort
    • splice
    • unshift
    • Non Mutating Methods

      every
    • filter
    • find
    • findIndex
    • forEach
    • map
    • reduce
    • reduceRight
    • some
    • toReversed
    • toSorted
    • toSpliced
    • with
    • Array Chaining
    • Callback Functions
    • Immutability Patterns
    • Shallow vs. Deep Copy
    • flat
    • flatMap
    • Easy Interview Questions
    • Medium Interview Questions
    • Hard Interview Questions
    • Deduplication
    • Filtering Data
    • Pagination
    • Search Functionality
    • Sorting UI
    • Code Examples: Array Recipes
    • Array Dashboard
    • Filter & Search App
JavaScript Array MasteryBasicsLength Property

Length Property

The length property of an array returns the number of elements it contains. It can also be used to truncate an array.

const fruits = ['Apple', 'Banana'];
console.log(fruits.length); // Output: 2

fruits.length = 1; // Truncating the array
console.log(fruits); // Output: ['Apple']
PreviousMutable vs. ImmutableNext Sparse Arrays