CC-10: Reading Objects

with Carmen Salas • 2024/10/21

slides

Objects

too eepy to take notes

Code Challenge

  1. Write a function named getAllKeys that takes in an object argument and logs all the keys in the given argument to the console.

const getAllKeys = (obj) => {
  Object.keys(obj).forEach((key) => {
    console.log(key);
  });
};

// getAllKeys(associateInstructorAges) // will log to the console: "carmen", "itzel", "zo"
  1. Write a function named getAllValues that takes in an object argument and logs the value of every key in the given argument to the console.

BONUS: 3. Write a function named sumAllValues that takes in an object argument and returns the sum of all the values of every key in the given argument.

Last updated