Nice work! In this lesson, we learned these concepts regarding arrays:
- Arrays are created with brackets
- Each item inside of an array is at a numbered position, or index, starting at
- We can access one item in an array using its index, with syntax like:
- We can also change an item in an array using its index, with syntax like
myArray = 'new string';
- Arrays have a
lengthproperty, which allows you to see how many items are in an array.
- Arrays have their own methods, including
.pop(), which add and remove items from an array, respectively.
- Arrays have many methods that perform different tasks, such as
.shift(), you can find documentation at the Mozilla Developer Network website.
- Some built-in methods are mutating, meaning the method will change the array, while others are not mutating. You can always check the documentation.
- Variables that contain arrays can be declared with
const. Even when declared with
const, arrays are still mutable. However, a variable declared with
constcannot be reassigned.
- Arrays mutated inside of a function will keep that change even outside the function.
- Arrays can be nested inside other arrays.
- To access elements in nested arrays chain indices using bracket notation.
Learning how to work with and manipulate arrays will help you work with chunks of data!
Looking for more ways to practice? Consider trying these:
- Use the
.lengthproperty to find the last element of an array.
- Use the other methods in MDN documentation not mentioned in the lesson.
- Take all the elements in an array and make a string.
- Find the return value of calling
.push()on an array.
- Nest an array within an array.
- Access an element in the nested array.
Take this course for free