CC-10: Reading Objects
with Carmen Salas • 2024/10/21
Objects
too eepy to take notes
Code Challenge
- Write a function named - getAllKeysthat 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"- Write a function named - getAllValuesthat takes in an object argument and logs the value of every key in the given argument to the console.
const getAllValues = (obj) => {
  Object.values(obj).forEach((value) => {
    console.log(value);
  });
};
// getAllValues(associateInstructorAges); // will log to the console: 22, 22, 23BONUS: 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.
const sumAllValues = (obj) => {
  return Object.values(obj).reduce((sum, val) => sum + val);
};
// console.log(sumAllValues(associateInstructorAges));Last updated