logo CodeStepByStep logo

countKeys

Language/Type: JavaScript json objects
Author: Melissa Hovik (on 2018/10/22)

Write a function named countKeys that takes a JavaScript object as a parameter and returns the number of keys in the object. For example, the following object has 3 keys ("i", "j", and "k"):

let counts = { "i" : 1, "j" : 2, "k" : 0 }

so the call countKeys(counts) should return 3. You may assume that the parameter passed to your function is a non-null JSON object.

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.