ericc
ericc

Reputation: 781

Javascript accessing multidimensional Array without knowing all keys

I have a little experience in Javascript and usually I found solution to my problems just by searching here or with Google But this time, I feel that I took the wrong path

I have build an Object (multidimensional associative array) like this : state["a"]["b"]["c"] = "idle";

If I know "a" and "c" but not "b", can I change the value "idle" , without looping through each keys ? taking into account that "c" is unique in the whole object

Something like : state["a"][*]["c"] = "busy";

Thanks in advance for your help

Upvotes: 0

Views: 90

Answers (1)

RJM
RJM

Reputation: 1178

If "c" only exists in one place as you've stated, then you'll need to loop through the items in the second dimension looking for the one that has a third dimension with an index of "c".

Upvotes: 1

Related Questions