0

If I have the following initialized... (fyi, in the code I'm basing it off of, both variables are dynamically created)

// Start of Code that MUST stay unchanged.
var myPrimaryArray = [["Potato","Walrus"],42,[["Your father was a hamster", "Target"],362]];
var locationArray = [2][0][1];
// End of Code that MUST stay unchanged

//What to put here to get "Target"?

How do I make this return "Target", with only those two variables? (Not knowing the depth into either array I have to go ahead of time.)

4

2 回答 2

3

Hopes this will return target

var myPrimaryArray = [["Potato","Walrus"],42,[["Your father was a hamster", "Target"],362]];
var locationArray = myPrimaryArray[2][0][1];
alert(locationArray);

output:

Target

To be fun , check your Code:

locationArray = myPrimaryArray [2][0][1];

于 2013-03-31T01:13:28.180 回答
0

Got a solution (altered text for stackoverflow, hope it still works for anyone seeking a solution similar to mine.) It's cumbersome, but it should work.

// Start of Code that MUST stay unchanged.
var myPrimaryArray = [["Potato","Walrus"],42,[["Your father was a hamster", "Target"],362]];
var locationArray = [2][0][1];
// End of Code that MUST stay unchanged


getArrayObjectWithLocationArray(myPrimaryArray,locationArray)



function getArrayObjectWithLocationArray(myArray, myLocationArray){
var myArray = stringToPositionArray(myString);
if (myLocationArray.length > 1}{
    return getPanelWithPositionString([myArray[myLocationArray[0]], myLocationArray.splice(0,1))
} else {
    return myArray[stringToPositionArray[0]];
}

}
于 2013-04-03T16:37:00.793 回答