Key Concepts

Review core concepts you need to learn to master this subject

Property .length

const numbers = [1, 2, 3, 4]; numbers.length // 4

The .length property of a JavaScript array indicates the number of elements the array contains.

Arrays
Lesson 1 of 4
  1. 1
    Organizing and storing data is a foundational concept of programming. One way we organize data in real life is by making lists. Let’s make one here: New Year’s Resolutions: 1. Keep a journal 2…
  2. 2
    One way we can create an array is to use an array literal. An array literal creates an array by wrapping items in square brackets []. Remember from the previous exercise, arrays can store any da…
  3. 3
    Each element in an array has a numbered position known as its index. We can access individual items using their index, which is similar to referencing an item in a list based on the item’s positi…
  4. 4
    In the previous exercise, you learned how to access elements inside an array or a string by using an index. Once you have access to an element in an array, you can update its value. let seasons =…
  5. 5
    You may recall that you can declare variables with both the let and const keywords. Variables declared with let can be reassigned. Variables declared with the const keyword cannot be reassigned. …
  6. 6
    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 newYear…
  7. 7
    Let’s learn about some built-in JavaScript methods that make working with arrays easier. These methods are specifically called on arrays to make common tasks, like adding and removing elements, mor…
  8. 8
    Another array method, .pop(), removes the last item of an array. const newItemTracker = [‘item 0’, ‘item 1’, ‘item 2’]; const removed = newItemTracker.pop(); console.log(newItemTracker); // Ou…
  9. 9
    There are many more array methods than just .push() and .pop(). You can read about all of the array methods that exist on the Mozilla Developer Network (MDN) array documentation . .pop() and .p…
  10. 10
    Throughout the lesson we went over arrays being mutable, or changeable. Well what happens if we try to change an array inside a function? Does the array keep the change after the function call or i…
  11. 11
    Earlier we mentioned that arrays can store other arrays. When an array contains another array it is known as a nested array. Examine the example below: const nestedArr = [[1], [2, 3]]; To acce…
  12. 12
    Nice work! In this lesson, we learned these concepts regarding arrays: * Arrays are lists that store data in JavaScript. * Arrays are created with brackets []. * Each item inside of an array is a…

What you'll create

Portfolio projects that showcase your new skills

Pro Logo

How you'll master it

Stress-test your knowledge with quizzes that help commit syntax to memory

Pro Logo