0

I am trying to access to a simple nested Array, doing this:

var currMenu = 1;
    while ( currMenu < menu.length ) {
        alert(currMenu);
        alert(menu[0][currMenu].text);
        currMenu++;
}

Despite alerts are throwing the correct values, I am getting this error on firebug: TypeError: menu[0][currMenu] is undefined.

What is happening?

Thanks!

Edit: Sorry, I was rushing, here you have the "menu" structure:

menu[0] = new Array();
menu[0][0] = new Menu(false, '', 15, 50, 20, '','' , 'navlink', 'navlink');
menu[0][1] = new Item('someText', '#', '', 100, 10, 1);

And the object Item:

function Item(text, href, frame, length, spacing, target) {
    this.text = text;
    if (href == '#') {
        this.href = '#';
    } else if (href.indexOf('http') == 0) {
        this.href = href;
    } else this.href = href;
    this.frame = frame;
    this.length = length;
    this.spacing = spacing;
    this.target = target;
    // Reference to the object's style properties (set later).
    this.ref = null;
    this.showLoadingBar = false;
}
3
  • Now what do we know about menu value? Commented Sep 20, 2012 at 14:02
  • sure you dont mean menu[currMenu].text ? Commented Sep 20, 2012 at 14:02
  • Sorry again, there is more data and object structure Commented Sep 20, 2012 at 14:18

2 Answers 2

3

Assuming your menu is coherent with the [0][currMenu], you should access it like this :

while ( currMenu < menu[0].length ) {
    alert(currMenu);
    alert(menu[0][currMenu].text);
Sign up to request clarification or add additional context in comments.

Comments

1

You're looking at the length of the "menu" array, but you're accessing the array at the zero-th index of that array (which may or may not be an array; I can't tell from the code you've posted).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.