Enjoy an ad free experience by logging in. Not a member yet?
Register .
01-23-2013, 12:03 AM
PM User |
#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
01-23-2013, 12:14 AM
PM User |
#2
Regular Coder
Join Date: Sep 2010
Location: London
Posts: 976
Thanks: 0
Thanked 203 Times in 198 Posts
Looks like you need to show the code that derives the value of i .
01-23-2013, 12:31 AM
PM User |
#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);
}
01-23-2013, 01:27 AM
PM User |
#4
Regular Coder
Join Date: Sep 2010
Location: London
Posts: 976
Thanks: 0
Thanked 203 Times in 198 Posts
That code appears to be performing the same operation 22 times, and reveals nothing.
01-23-2013, 01:38 AM
PM User |
#5
Supreme Master coder!
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,056 Times in 4,025 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.
01-23-2013, 02:55 AM
PM User |
#6
Senior Coder
Join Date: Nov 2010
Posts: 2,461
Thanks: 52
Thanked 457 Times in 455 Posts
Quote:
Originally Posted by
Logic Ali
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...
01-23-2013, 03:26 PM
PM User |
#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.
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 06:26 PM .
Advertisement
Log in to turn off these ads.