Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-23-2013, 12:03 AM   PM User | #1
korssane
Regular Coder

 
Join Date: Jun 2011
Posts: 148
Thanks: 18
Thanked 0 Times in 0 Posts
korssane is an unknown quantity at this point
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
korssane is offline   Reply With Quote
Old 01-23-2013, 12:14 AM   PM User | #2
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 976
Thanks: 0
Thanked 203 Times in 198 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Looks like you need to show the code that derives the value of i.
Logic Ali is offline   Reply With Quote
Old 01-23-2013, 12:31 AM   PM User | #3
korssane
Regular Coder

 
Join Date: Jun 2011
Posts: 148
Thanks: 18
Thanked 0 Times in 0 Posts
korssane is an unknown quantity at this point
Code:
for (i=0; i<22 ; i++)
														
{															
																											var pr_id = res.data[i][1];
$(proj_val).val(pr_val);	


}
korssane is offline   Reply With Quote
Old 01-23-2013, 01:27 AM   PM User | #4
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 976
Thanks: 0
Thanked 203 Times in 198 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
That code appears to be performing the same operation 22 times, and reveals nothing.
Logic Ali is offline   Reply With Quote
Old 01-23-2013, 01:38 AM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,056 Times in 4,025 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 01-23-2013, 02:55 AM   PM User | #6
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
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...
xelawho is offline   Reply With Quote
Old 01-23-2013, 03:26 PM   PM User | #7
korssane
Regular Coder

 
Join Date: Jun 2011
Posts: 148
Thanks: 18
Thanked 0 Times in 0 Posts
korssane is an unknown quantity at this point
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.
korssane is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:26 PM.


Advertisement
Log in to turn off these ads.