Victor Kimura
asked on
how to find if a key name exists in a JSON object
Hi,
I have this JSON object:
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 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<><
I have this JSON object:
var jTest = {
"couponCodeOne": [
"standard",
"gold",
"platinum"
],
"couponCodeTwo-3": [
"gold",
"platinum"
]
};
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");
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER