Checking object has value

Tell us what’s happening:

  **Your code so far**
    function isEveryoneHere(obj) {
// Only change code below this line
 for(let i=0;i<obj.length;i++)
 {
   if(obj.hasOwnProperty(obj[i]))
           return true;
 }
// Only change code above this line
 return false;
}
console.log(isEveryoneHere(users));

In this function I have written code of using iterations in users obj for false values it showing correct values but for checking values in it is showing incorrect results? Any suggestions?

  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.190 Safari/537.36.

Challenge: Check if an Object has a Property

Link to the challenge:

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thankyou so much :blush:

Hi!
i<obj.length It seems that you are using length method here on an object. This will return undefined as it is array method. Try for…in loop to iterate through the object key-value pairs.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.