# Tough struct ( Resolved )

We have a stuct var, say, myStruct,
Its values could be like the following, however, the Element values on the Left side could be other datetime value, for instance, the top left Element value could be, “10/12/20 13:24” instead, that is,
the left element values are unknown to us. The challenge: how to retrieve the value of the “4. close” , in this case, it would be 3463.78.

``````10/12/20 03:34 PM	Struct (ordered)
1. open		3462.5346
2. high		3465
3. low		3460.6403
4. close	3463.78
5. volume	14128
10/12/20 03:33 PM	Struct (ordered)
1. open		3460.73
2. high		3464.015
3. low		3459.43
4. close	3461.99
5. volume	11654
``````

You, frankly, haven’t given the right information to give you an answer. It would have been far easier to digest had you just shown us the actual ordered struct you’re working with codewise. Something along the lines of:

``````myStruct = {
varOne = [
subVarOne = valueOne,
subVarTwo = valueTwo,
subVarThree = valueThree
]
};
``````

In which case, getting a value would be myStruct.varOne.subVarThree, for example.

HTH

– Denny

@ddspringle This question was cross-posted in the CFML Slack team and answered there yesterday. @justaguy Please update posts like this if you are going to cross post them and you get an answer in one of those places.

3 Likes

It would also be very nice to always see your final solution, so that:
1.others can stop wasting time searching a solution for you, and
2. others can see your solution in the future, just in case they get stuck with some similar question.

The solution in CFML Slack (provided by @John_Whish) to be able to access a key of an ordered struct by position looked like this.

``````key = structKeyArray(data)[4];
writeDump(data[key]);
``````

So that code would access the 4th key in the struct regardless of what it’s name was.

2 Likes