1

I am attempting to get the key and value data from an object that is inside an object.

Example:

$.each(my_object, function(key, value)
{
    // some code

    if (typeof value === object)
    {
        $.each(value, function(key, value)
        {
            // do something
        )};
    }
});

Unfortunately, I am getting the following error:

object is not defined

Any help?

2 Answers 2

5

Your error clearly states that object is not defined. That is because you are trying to use it like a variable.

When checking typeof values you should be using a string comparison:

if (typeof value === 'object')
{
}
Sign up to request clarification or add additional context in comments.

2 Comments

Oh, whoops :) Thanks.
I'm not sure why, but I was thinking there was something wrong with the value variable that I was comparing.
0

you have syntax error and object in the if condition must be string

this is the right code :

$.each(obj, function(key, value)
{

    if (typeof value === "object")
    {
        $.each(value, function(key, value)
        {
            console.log(value)
        }); //syntax error here
    }
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.