Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts

    getting error with array of array element value

    Hi Guys ,

    i have an array with the following structure:


    data:
    [
    [1807,1807,"name1","Test1"],
    [1807,1807,"name2","Test1"],
    [1807,1807,"name3","Test1"],
    [1807,1807,"name4","Test1"],
    [1807,1807,"name5","Test1"],
    [1807,1807,"name6","Test1"]
    ]


    Iam trying to get the value

    var pr_id = res.data[i][1];

    if i replace "i" with a value this will work in both chrome and IE8 with no error. But as soon as I use my index "i" , this works in chrome but not in IE.
    I have the following error :



    Code:
    Message: 'data[...].1' is null or not an object
    Line: 354
    Char: 16
    Code: 0
    Any help?

    Thanks

  • #2
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    Looks like you need to show the code that derives the value of i.

  • #3
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Code:
    for (i=0; i<22 ; i++)
    														
    {															
    																											var pr_id = res.data[i][1];
    $(proj_val).val(pr_val);	
    
    
    }

  • #4
    Senior Coder Logic Ali's Avatar
    Join Date
    Sep 2010
    Location
    London
    Posts
    1,028
    Thanks
    0
    Thanked 207 Times in 202 Posts
    That code appears to be performing the same operation 22 times, and reveals nothing.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,901
    Thanks
    79
    Thanked 4,422 Times in 4,387 Posts
    One *POSSIBLY* right answer might be:
    Code:
    for ( var i = 0; i < data.length; ++i )
    {
        mynum = data[i][1];
        ... and do something with mynum here ...
    }
    But why you would do a loop from 0 to 21 when there are only 6 elements in the array...makes no sense at all.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,980
    Thanks
    56
    Thanked 557 Times in 554 Posts
    Quote Originally Posted by Logic Ali View Post
    That code appears to be performing the same operation 22 times, and reveals nothing.
    truly. but if you scroll waaaaaay over to the right there you'll see:
    Code:
    var pr_id = res.data[i][1];
    why, when pr_id is never used inside the loop, is another mystery.

    but Old Pedant nailed it - what's the point in trying to loop 22 times over a 6 item array? Chrome still errors out:
    Code:
    Uncaught TypeError: Cannot read property '1' of undefined
    as does IE, as you say:
    Code:
    'data[...].1' is null or not an object
    maybe if you explained what it is that you're trying to do? because using data.length instead of 22 would seem to be the logical solution...

  • #7
    Regular Coder
    Join Date
    Jun 2011
    Posts
    148
    Thanks
    18
    Thanked 0 Times in 0 Posts
    hi Guys,

    do not know what was the problem but as soon as i removed a js library ..the errro disapears..so what was wrong i do not know..

    Thanks for your precious help.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •