vincent
vincent

Reputation: 1313

detecting if object has children or not

I have the following problem, i have to know if an element has children or not. if the object looks a followed:

Object [
    Object[["name" : "lisa"], ["age" : "14"], ["gender" : "female"]],
    Object[["name" : "bjorn"], ["age" : "40"], ["gender" : "male"]],
    Object[["name" : "zoe"], ["age" : "24"], ["gender" : "female"]]
]

it should follow 1 route, if it looks as following:

 Object[["name" : "lisa"], ["age" : "14"], ["gender" : "female"]]

it should follow another route. In general, the first example object is a collection of the second example object. so in other words:

if (example 1) {
 ...do this...
} else if (example 2) {
 ...do that...
}

Upvotes: 0

Views: 187

Answers (1)

Jonatan Hedborg
Jonatan Hedborg

Reputation: 4432

Your syntax looks weird. The normal way of defining an object (eg hashmap) would be

var myObj:* = {}
//Or if it's an array, as in your case;
var myArr:Array = [{name: "lisa", age:14, gender:"female"}, {...etc}]

There's no easy way to see if an object has entries however. This is how I usually do it;

var hasEntries:Boolean = false;
for(var key:String in myObj) {
  hasNodes = true;
  break;
}

Upvotes: 1

Related Questions