I was searching to get a result for this either and I ended up with;
const MyObject = {
SubObject: {
'eu': [0, "asd", true, undefined],
'us': [0, "asd", false, null],
'aus': [0, "asd", false, 0]
}
};
For those who wanted the result as a string:
Object.keys(MyObject.SubObject).toString()
output: "eu,us,aus"
For those who wanted the result as an array:
Array.from(Object.keys(MyObject))
output: Array ["eu", "us", "aus"]
For those who are looking for a "contains" type method: as numeric result:
console.log(Object.keys(MyObject.SubObject).indexOf("k"));
output: -1
console.log(Object.keys(MyObject.SubObject).indexOf("eu"));
output: 0
console.log(Object.keys(MyObject.SubObject).indexOf("us"));
output: 3
as boolean result:
console.log(Object.keys(MyObject.SubObject).includes("eu"));
output: true
In your case;
var myVar = { typeA: { option1: "one", option2: "two" } }_x000D_
_x000D_
// Example 1_x000D_
console.log(Object.keys(myVar.typeA).toString()); // Result: "option1, option2"_x000D_
_x000D_
// Example 2_x000D_
console.log(Array.from(Object.keys(myVar.typeA))); // Result: Array ["option1", "option2" ]_x000D_
_x000D_
// Example 3 as numeric_x000D_
console.log((Object.keys(myVar.typeA).indexOf("option1")>=0)?'Exist!':'Does not exist!'); // Result: Exist!_x000D_
_x000D_
// Example 3 as boolean_x000D_
console.log(Object.keys(myVar.typeA).includes("option2")); // Result: True!_x000D_
_x000D_
// if you would like to know about SubObjects_x000D_
for(var key in myVar){_x000D_
// do smt with SubObject_x000D_
console.log(key); // Result: typeA_x000D_
}_x000D_
_x000D_
// if you already know your "SubObject"_x000D_
for(var key in myVar.typeA){_x000D_
// do smt with option1, option2_x000D_
console.log(key); // Result: option1 // Result: option2_x000D_
}
_x000D_