I’ve been stuck on a teaching exercise for the better part of 2 days, and I decided I needed some help. I have to write a function called keys that returns an array of all the keys in the object without using object.keys();. I was able to turn everything into a string simply enough, and print everything using object.values(); but now I want to take what I obtained using object.values, and return just the key(As right now it returns key and value I.E – A:1, B:2, C:3 I want just ABC).
So far, this is a code I was trying. Please be kind, I am doing my best!
function keys(json) {
var obj = JSON.parse(json);
*//My code starts here*
const keys = Object.values(obj);
keys.toString();
for (const [key] of Object.Entries(obj)) {
return(key);
}
*//My code ends here*
}
There is “inputs” that test my code, they are below and represented in obj
first input:
{"a":"1","b":"2","c":"3"}
second input:
{"first":"Matt","last":"Lane"}
third input:
{}