-
Notifications
You must be signed in to change notification settings - Fork 17
Open
Description
Takes in an object and a function and calls the function as many times as there are key/value pairs with each key, value. It's like you're creating a forEach function for objects. For each key/value pair in the object, you'll be doing calling the function to each of those key/value pairs. Also, map is a native method in Javascript which means doing the same thing to every element in the array. So you're essentially writing a map method for objects!
Example 1:
const obj1 = {
name: 'Maricris',
age: 24,
};
const func1 = (key, value) => {
console.log(`Key/Value Pair = ${key}: ${value}`);
};
Input: (obj1, func1)
Output:
Key/Value Pair = Name: Maricris
Key/Value Pair = Age: 24
Example 2:
const obj2 = {
curriculum: 'HTML',
challenges: 3,
students: 'Kinue + Saumya +Amey',
level: 5,
};
const func2 = (key, value) => {
console.log(`Key/Value Pair = ${key}: ${value}`);
};
Input: (obj2, func2)
Output:
Key/Value Pair = curriculum: HTML
Key/Value Pair = challenges: 3
Key/Value Pair = students: Kinue + Saumya + Amey
Key/Value Pair = level: 5
Metadata
Metadata
Assignees
Labels
No labels