Link to home
Start Free TrialLog in
Avatar of Victor Kimura
Victor KimuraFlag for Canada

asked on

how to find if a key name exists in a JSON object

Hi,

I have this JSON object:

var jTest = {
            "couponCodeOne": [
                    "standard",
                    "gold",
                    "platinum"
                ],
            "couponCodeTwo-3": [
                    "gold",
                    "platinum"
                ]
        };

Open in new window


I'm trying to find if the key name 'couponCodeOne' exists in the JSON object or not.

I was using qUnit to test it like:

var iInArray = $.inArray(jTest, 'couponCodeOne');
        assert.notEqual(iInArray, -1, "Passed. couponCodeOne is found in JSON object");

Open in new window


var iInArray should be NOT be equal to -1 but it is right now.

I guess there is some other way.

I'm thinking $.each(jTest, function() {...});

But is there another shorter way like using $.inArray. I don't think there is a $.inObject but then I'm told an array is an object.

Much thanks and Father bless<><
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Victor Kimura

ASKER

Thanks, guys! =)