Array Prototypes

Learning Goals

In this lesson we’ll cover:

Vocabulary

  • Array Prototype - methods that are built specifically for arrays. They help us change the arrays themselves or get certain information out of them.
  • Mutator - methods that mutate, or change, the original array
  • Accessor - methods that do not mutate the original array, rather just give us some information about the array

Warm Up

Protocol

Throughout most of this lesson, you’ll be working in small groups to explore both

  • some array prototypes
  • different ways to learn new technical concepts, and which you like best

Instructor resource

For each array prototype method, follow this protocol carefully:

  1. Read the documentation on MDN.
  2. Talk through your understanding of it together. Make a visual representation of the method with your candies and paper.
  3. Predict: What is returned from the method?
  4. Predict: Does the method mutate the original array?
  5. Try It: In a repl.it, try out the method. While poking around here, try to verify your predictions from steps 3 and 4.
  6. Back to documentation - verify your predictions from steps 3 and 4.
  7. Document any remaining questions!

In your new group of 3, make an anchor chart for your assigned array prototype! It should include:

  • Name of method
  • What it does (in plain English)
  • Does it mutate the original array?
  • What does it return
  • Optional: Syntax examples, use-case examples.

After all anchor charts are made, we will do a “Gallery Walk” - walk around the room and look at each others posters and make sure notes are accurate. If you aren’t 100% of something you are about to write on your poster - totally ok to ask an instructor! We do want to make sure these provide accurate info for your classmates.

Wrap Up

What should you memorize?

Often times, especially when we are starting to code, we put pressure on ourselves to memorize every little thing. This is NOT necessary and not a good use of your brain space! There will be some methods you use so frequently that you just memorize them, but for the most part, the things you “memorize” should be bigger ideas and how things work together.

Some of the methods we learned today are the kind you’ll use so often that you’ll have down pat (including the syntax): push, pop, shift, unshift.

You should have enough of an understanding of arrays that you know you could google something like “remove a specific element from an array”, but maybe you won’t memorize exactly what method to use or the exact syntax for it.

What is not worth memorizing?

It’s not a good use of time to attempt to memorize every array prototype and its syntax.

Reflection

  1. What from this morning helped you learn? Talking with your partner? Spending time in the docs? Playing with a method in repl.it? Visualizing it without code (using candies)?
  2. Discuss your best learning techniques with your table/partner.
  3. Open your notebooks to the last page, and write “When I’m stuck, I will:” and then add the learning strategies that worked best for you!

Lesson Search Results

Showing top 10 results