Given a JS Object:
var obj = {
a: {
b: {
c: {}
}
}
};
How can i convert obj.a.b
into string "obj.a.b"
to count how many objects (3) have been used? In this case obj.a.b
: 3. I have tried ''+obj.a.b
, uneval()
, toSource()
, toString()
, for...in
, Object.key().length
but it is not what i want to know.
I imagine it's not possible... but not sure.
For example why i want:
function h (o) {
let a = o.split('.');
if (a.length > 2) {
alert('not allowed'); // because obj.a.b > 2
return;
} else {
// because obj.a == 2 -> ok. process with obj.a ..
}
}
h(obj.a.b);