I have an object inside an object which and I want to get its length. I tried with Object.keys(obj).length but it shows the length of the parent object I want also to get the length of the child object.
Here's the code I tried.
let data = { 'data': { '0x': { 0: { 0: 'test1', 330: 'test2' } } } }; let hideCtrls = false; if(Object.keys(data.data).length == 1){ let objIn = Object.values(data.data); if(Object.values(objIn)[0] == 1) { hideCtrls = true; } else { hideCtrls = false; } }; console.log(hideCtrls); I want to check the length of data inside data, if it's length is 1 I want to check the length of the values inside the first object (in this case it is 0x). If the length the child object is also 1 I want to set hideCtrls to true.
I want to get the length of the this last object 0: { 0: 'test1', 330: 'test2' }. Here we have two key value pairs inside so it should return false, if it has only one key value pair it should return true.
NOTE: The keys are dynamic