473,587 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Undefined error when accessing 2-D array contents

8 New Member
Hi,

Every time I try to access the contents of the following array it returns that it is undefined. I have tried multiple variations on accessing the arrays syntax wise but get different errors every time.

When I try to do it the way listed below I get the undefined error I talked about before.

Code:

Expand|Select|Wrap|Line Numbers
  1.     var array = new Array();
  2.     var i, j, txt;
  3.     var str = new Array();
  4.  
  5.     try{
  6.         array = document.tsv.read_in("u:\\test.txt");
  7.         for(i=0;i<array.length;i++)
  8.             str[i]=array[i];
  9.         for(i=0; i<array.length; i++)
  10.             array[i] = new Array();
  11.     }
  12.     catch(err)
  13.     {
  14.         txt="There was an error on this page.\n\n";
  15.         txt+="Error description: " + err.description + "\n\n";
  16.         txt+=err.stacktrace + "\n\n";
  17.         txt+=err.stack + "\n\n";
  18.         txt+="Click OK to continue.\n\n";
  19.         alert(txt);
  20.     }
  21.  
  22.     for(i=0; i<array.length; i++)
  23.     {
  24.         var str2 = str[i];
  25.         var temp = str2.split("\t");
  26.         for(j=0;j<temp.length;j++)
  27.         {
  28.             array[i][j] = temp[j];
  29.         }
  30.         document.write(array[0][0]);
  31.     }
  32.  
  33.     for (i=1;i<array.length; i++)
  34.     {
  35.         document.write("<div class=\"silverheader\" id=\""+i+"\"><a href="+i+">"+array[i][0]+"</a></div>");
  36.         document.write("<div class=\"submenu\">");
  37.         for(j=0;j<temp.length;j++)
  38.             document.write(array[i][j]+"\t");
  39.         document.write("</div>");
  40.     }
I realize the code above is ridiculously inefficient but I'm just trying to figure out what I'm doing wrong. Any suggestions?
Attached Images
File Type: jpg screenshot_webpage.jpg (6.3 KB, 157 views)
Jun 9 '10 #1
16 1912
Dormilich
8,658 Recognized Expert Moderator Expert
line #6, you’re overwriting your array variable.
Jun 9 '10 #2
manutd7
8 New Member
@Dormilich
That's my initializing line, the array has nothing in its contents before that point.
Jun 9 '10 #3
Dormilich
8,658 Recognized Expert Moderator Expert
that doesn’t matter. whatever it has been before, after line #6 it’s something different.
Jun 9 '10 #4
manutd7
8 New Member
Yea, that's what I was going for cause that's when the contents of the array are first filled. I should have probably said this in the first post but during my debugging attempts I accessed the contents of the array after line 6, and I got the correct output - that is the contents that I brought in with the read_in function. When I try and access the contents in line 30 I get undefined for all index values. So I doubt that line 6 is where my problem is.
Jun 9 '10 #5
Dormilich
8,658 Recognized Expert Moderator Expert
do you have a test page, where I can look for myself?
Jun 9 '10 #6
gits
5,390 Recognized Expert Moderator Expert
simplyfied it a bit to test in firebug-console -> basically it seems to work:

Expand|Select|Wrap|Line Numbers
  1. var my_array = [];
  2. var str      = [];
  3. var i, j, txt;
  4.  
  5.  
  6. my_array = ['foo\t8\tbar', 'foo','foo','foo','foo','foo'];
  7.  
  8. for (i = 0; i < my_array.length; i++) {
  9.     str[i]   = my_array[i];
  10.     my_array[i] = [];
  11. }
  12.  
  13. for(i = 0; i < my_array.length; i++) {
  14.     var str2 = str[i];
  15.     var temp = str2.split("\t");
  16.  
  17.     for(j = 0; j < temp.length; j++) {
  18.         console.log(temp[j]);
  19.  
  20.         my_array[i][j] = temp[j];
  21.  
  22.         console.log(my_array[i][j]);
  23.     }
  24. }
  25.  
  26. console.log(my_array);
  27.  
how does the array initially look like?
Jun 10 '10 #7
manutd7
8 New Member
gits,

I have attached the result of the code that you pasted above which still gives me the same "undefined" response when I try to access the 2-d array. Initially, the array consists of a line from a tsv file that is parsed in using the java read_in function that I created.

If I try to access the array using the syntax "array[i,j]" I get the problem where each interation of the outer for loop overwrites the same row of the 2-d array. Basically at the end I have a 2-d array that has the same info throughout. Anybody have any answers to why I'm having these problems?
Jun 10 '10 #8
gits
5,390 Recognized Expert Moderator Expert
what the code ... in fact yours ... produce is the following for my_array:

Expand|Select|Wrap|Line Numbers
  1. [["foo", "8", "bar"], ["foo"], ["foo"], ["foo"], ["foo"], ["foo"]]
is that what you expect?

since you use temp which has the las split operation's result assigned at this time there might be undefined values since temp might have had different lengths ...
Jun 10 '10 #9
manutd7
8 New Member
Yea that's the output I expect but unfortunately don't get. The temp arrays all have the same length as I'm inputting from a tsv file that has the same number of columns for the entire document.

Could it be a problem with the way my compiler or javascript settings on my browser? Cause if it works for you guys then there shouldn't be a reason why it doesn't work for me.
Jun 10 '10 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

2
4076
by: Christopher Johannsen | last post by:
Good Day: I am working on building a tool Using ASP/COM & IIS5.1 for a non-administrative technical support team to change domain passwords for users. I have the basic interface built and working from my developement machine (Windows XP Pro SP 1A) which is hosting the pages for now. The problem is that when I try to access the site from a...
4
2280
by: KKramsch | last post by:
My code is generating this type of error: Security Error: Content at http://nonexistent.org/somepage.html may not load data from about:blank. The "about:blank" page mentioned in the error message is a pop-up window, whose content is 100% dynamically-generated, and which is in fact *owes its existence* to code in the referring page...
4
10620
by: leslie_tighe | last post by:
Hello, I have a method on a com+ object that is returning an array of objects. I know the array is popluated as calls to check the ubound and lbound show valid values. However, any calls to get the value of a cell in the array results in a type mismatch error.
0
1514
by: mad | last post by:
I am new here and don't know if someone has encountered and discussed this problem before. I appreciate any help to this problem. I am building a new Oracle database (8.1.7) and Win 2000/IIS 5 for development. After I moved ASP pages over from another server (also Oracle 8.1.7 and Win 2000/IIS 5), the error occurred when recordset's...
1
1763
by: arunkv | last post by:
Hi Guys ... This problem has been bugging me for over 5 days now. I am trying to access a web service running in a Tomcat Server (a Linux box) via a C#.Net page and I get the following error: "The underlying connection was closed: An unexpected error occurred on a receive." The flow is as follows.
1
1376
by: ken.beutler | last post by:
I am getting a 404 error when trying to access an ASP page from a remote machine (via Internet Explorer). However, the asp page is processed successfully when accessing this page from the local machine. I checked permissions from IIS administration and from explorer and nothing seemed out of the ordinary. Other ASP pages work from other...
0
1347
by: gakhanna | last post by:
Hi, I am getting the following error when I tried connecting to Task Center. In task center I have scheduled daily incremental backup which also didnt ran. Here comes the Error which I am getting: DBA1177N A database connection to the Tools Catalog Database "TOOLSDB" cannot be made. SQLCODE "-22205" Explanation:
2
1804
by: RogerInHawaii | last post by:
I would like to pass an array by reference to a function so that I can modify the contents of the array and effectively "return" that array to the caller. I tried doing this: function MyFunction(&$MyArray) { MyArray = "First"; MyArray = "Second"; }
3
5625
by: Nathan Sokalski | last post by:
When I attempt to access a Microsoft Access database from my website, I recieve the following error: Server Error in '/' Application. -------------------------------------------------------------------------------- Security Exception Description: The application attempted to perform an operation not allowed by the security policy. To...
1
1938
by: sayid | last post by:
Hello, I have a problem when altering a DIV-element from another frame. The frameset looks like this: <frameset rows=0,0,* border=0> <frame name=header src=/header.htm scrolling=no noresize="true" frameborder=0> <frame name=border src=/border.htm scrolling=no noresize="true" frameborder=0> <frameset cols=200,* border=0>...
0
7920
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5718
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3844
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.