- Home /
Iterate though hashtable to return element keys not values
I am trying to figure out how you would iterate through a hashtable and get their key names or element names instead of their value. So for instance:
[client_name, Mike]
[age, 26]
[height, 5"3"]
So for instance if I wanted to do a for loop or for each I would be able to return "client_name, age, and height" rather then their values. I am working in Javascript.
Can anyone help me out?
Answer by Senhor de todo o Mal · Feb 02, 2011 at 04:26 PM
You can just use the Keys property.
For example:
var table:Hashtable = new Hashtable();
table["client_name"] = "Mike";
table["age"] = 26;
table["height"]= "5\"3\"";
for(var str:String in table.Keys){
//do stuff
}
Awesome, have any idea how this would go if I were using a regular for loop like for(i=0; i
You can copy into an array using table.$$anonymous$$eys.CopyTo(array,0) and iterate through the array using the regular for loop. But if index is important it would be a better idea to just use a different type of collection. What xml parser are you using?
It is a custom build parse built by someone else her at my job. Not a standard one we grabbed from the net.
Answer by volkan · Jun 10, 2012 at 09:52 AM
this is old, probably you've found the solution and i'm sure that it'll will help someone else.
var hash = { client_name: Mike, age: 26, height: 5"3" };
for (item in hash.Key){ Debug.Log(hash.Key.toString()); }
Your answer
Follow this Question
Related Questions
Default Null Value for Key Not Found in Dictionary? 1 Answer
hashtable key or value index? 2 Answers
Getting a key value from a hashtable? 1 Answer
How to call value by key when key is an object? 1 Answer
access Input.GetButton key name 1 Answer