In my Javascript code I defined a variable of type Array, which will be populated with the entities retrieved from Dynamics Crm.
I need to check if the variable is populated both when it's a simple array and when it has become an array of entities: my code only works in the first case (for the simple array)
I defined the variable this way:
var arrayOfEntities = new Array();
This is the code to check whether the array is empty:
if (arrayOfEntities.length != 0) { return arrayOfEntities; }
The second time the previous instruction will be hit, arrayOfEntities will be already populated, so that I need to modify the condition: in fact, by asking if (arrayOfLength != 0), the condition is valued true even when there aren't entities in there.
I assume that the problem is that a simple array has a different structure than an array of entities: in the second case, "length" is a child node of "entities".
How can I modify my condition to make it valid in both cases?