I am busy with a javascript program where I have a function that runs through values and outputs only the certain values that I specified.
let printValuesOf = (jsObject, keys) => {
for (let i = 0; i <= keys.length; i++) {
let key = keys[i];
console.log(jsObject[key]);
}
}
let simpsonsCatchphrases = {
lisa: 'BAAAAAART!',
bart: 'Eat My Shorts!',
marge: 'Mmm~mmmmm',
homer: "d'oh!",
maggie: "(Pacifier Suck)",
};
printValuesOf(simpsonsCatchphrases, 'lisa', 'bart', 'homer');
// Expected console output:
// BAAAAAART!
// Eat My Shorts!
// d'oh!
// Returns undefined
2
Answers
you can modify the
printValuesOf
function to accept anarray
ofkeys
instead ofmultiple arguments
.Try this:
Take a look at this,