Skip to content

Instantly share code, notes, and snippets.

@rogerwschmidt
Last active June 8, 2017 21:56
Show Gist options
  • Select an option

  • Save rogerwschmidt/1e371ff3eb0a3f056bc90d1a2054f21c to your computer and use it in GitHub Desktop.

Select an option

Save rogerwschmidt/1e371ff3eb0a3f056bc90d1a2054f21c to your computer and use it in GitHub Desktop.

Arrays, Objects & Iterations Instructor Notes

Objectives:

  • Create and manipulate arrays and objects
  • Explain the difference between object dot notation and bracket notation
  • Explain how objects are stored and compared in memory
  • Write a for loop to iterate over an array
  • Write a for-in loop to iterate over an object
  • Describe common native methods for arrays and objects
  • Write a deeply nested object
  • Read data from a deeply nested object

Create and manipulate arrays and objects

Answer in your slate:

  • Create and assign an empty array to a variable
  • Create and assign an array with the values 1,2,3 to a variable
  • Create and assing an empty object to a variable
  • Create and assign an object with key of 'name' and a value of 'Roger'
  • Given the array var ar = [1,2,3,4], access the 2nd value in the array?
  • Given the array var ar = [1,2,3,4], change the 1st value in the array to 0
  • Given the object var obj = { name: 'Roger' }, access the value of the key 'name'
  • Given the object var obj = { name: 'Roger' }, change the value of the key 'name' to be 'Charlemagne'

Explain the difference between object dot notation and bracket notation

Turn to your neighbor and explain the difference between dot notation and bracket notation. Be prepared to share your answer with the class.

Explain how objects are stored and compared in memory

  • Turn to your neighbor and explain how objects are stored in memory. Be prepared to share your answer with the class.
  • Turn to your neighbor and explain how objects are compared. Be prepared to share your answer with the class.

Write a for loop to iterate over an array

In your slate, write a for loop to print out the contents of the following array var arr = [1,2,3,4,5,6]

Write a for-in loop to iterate over an object

In your slate, write a for-in loop to print out the values of the following object.

var obj = { name: 'Roger', hair: true, shirt: 'plaid', glasses: false, age: 33 }

Describe common native methods for arrays and objects

Turn to your neighbor and describe methods for arrays and objects. Be prepared to share with the class

Write a deeply nested object

  • What is an example of data that could be expressed in a nested objects
  • On your desks, write a deeply nested object.

Read data from a deeply nested object

  • On your slate, write down how to access a key/value in your deeply nested object.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment