Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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.)

share|improve this question
i have updated my answer , check it out! – IOIO MAD Mar 31 at 1:26
I appreciate the updated answer, but you're still changing one of the initial vars, sorry if I'm unclear, ... the point is those are the initial vars I have to start out with. Both those vars will be dynamically generated, which is why I can't change them. As such, this assumes I don't actually know what the value in location array will actually be, or the actual layout of myPrimaryArray. All I know is that location array holds the position of where in myPrimaryArray "Target" is. If I could do something like "MyNewVar = myPrimaryArray[locationArray] that'd be great, but I don't think it works. – liljoshu Apr 1 at 18:36

2 Answers

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];

share|improve this answer
1  
+1, even if your grammar sucks (Hopes?). :-) – RobG Mar 31 at 1:16
I appreciate the suggestion, but the code I'm providing is what I have to work with (it's an example of something I can't really change). The point is that I have to get "Target" from myPrimaryArray using locationArray as its provided. Changing the locationArray isn't an option for me. – liljoshu Mar 31 at 1:20
@RobG ha ha !, Sorry , for my bad english! – IOIO MAD Mar 31 at 1:22
That's cool, my English is pretty rubbish at times too, and it's my first language! – RobG Mar 31 at 1:44
up vote 0 down vote accepted

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]];
}

}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.