Problem Description
Write a function collectKeys(obj) that takes an object. Return an array of all the keys in that object, but converted to uppercase.
Input:
{ id: 1, city: "NY" }Step 1: Get the keys (array).
Step 2: Map over them to uppercase.
Return:
["ID", "CITY"]
Explanation of object Iteration tools:
Here is the problem: Arrays are easy to loop over. Objects are not.
const user = { name: "Alice", age: 25, role: "Admin" };
// user.map(...) // ❌ CRASH! Objects don't have .map()
// user.forEach(...) // ❌ CRASH!
To loop over an object, we use a "Static Method" to convert the Object into an Array. The first tool is: Object.keys(obj)
It returns an array of the property names (keys).
const keys = Object.keys(user);
// ["name", "age", "role"]
// NOW you can use .map() or .forEach() on 'keys'!