Tell us what’s happening:
I can’t quite understand why this code does not work?
**Your code so far**
function orbitalPeriod(obj) {
for(const key in obj) {
if(obj.hasOwnProperty(key) === "name") {
console.log("found!")
}
}
}
orbitalPeriod({name: "iss", avgAlt: 413.6});
**Your browser information:**
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36
Challenge: Map the Debris
Link to the challenge:
ilenia
October 16, 2021, 12:37pm
2
egorulybin:
obj.hasOwnProperty(key)
what is the output of this?
Follow up question…
Is there a way to do anything to that ‘key’ now that I have matched it.
For example… when I try to delete the key that matched the name prop, it doesn’t work…
if(key === “name”) {
delete key;
}
ilenia
October 16, 2021, 1:09pm
5
key
is a string, do you want to delete a property from the object? then you need to use the right notation to identify that property
system
Closed
April 17, 2022, 1:09am
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.