Array problem

Hi,

imagine this:

var fileArray = new Array();

      function addFile(tableID, fileName, fileSize, dateString, dimX, dimY) {

            if (fileArray.length) var currentIndex = fileArray.length;
            else var currentIndex = 0;

            fileArray[currentIndex] = new Object();
            fileArray[currentIndex]["fileName"] = fileName;
            fileArray[currentIndex]["fileSize"] = fileSize;
            fileArray[currentIndex]["dateString"] = dateString;
            fileArray[currentIndex]["dimX"] = dimX;
            fileArray[currentIndex]["dimY"] = dimY;

            clearFileList(tableID);                  
            updateFileList(tableID);

            dw_scrollObj.scrollTo(tableID+'_wn',0,((fileArray.length-1)*150));      

            //print_r(fileArray,0);

      }

Now, my actual problem is, that everytime i add such an Element to the array, i also do get an "undefined" element in the array. I tried to pop() it out but this pops out the one i added. I tried to use push(object) instead of the above code to add a new element, but also there i do get an "undefined" element.

Any ideas on this?

LVL 1
spiritwithinAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
Where do you see the "undefined" element ?
spiritwithinAuthor Commented:
I use some cheap print_r clone for javascript to inspect the array. That's where i see the undefined element. Besides that i pass the array to an image sorter tool which then shows up an image called "undefined".
ozoCommented:
I don't see an undefined element using
function print_r(theObj){
  if( theObj.constructor == Array ||
     theObj.constructor == Object
  ){
    document.write("<ul>")
    for(var p in theObj){
      if( theObj[p].constructor == Array||
         theObj[p].constructor == Object
      ){
        document.write("<li>["+p+"] => "+typeof(theObj)+"</li>");
        document.write("<ul>")
        print_r(theObj[p]);
        document.write("</ul>")
      }else{
          document.write("<li>["+p+"] => "+theObj[p]+"</li>");
      }
    }
    document.write("</ul>")
  }
}



Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Languages and Standards

From novice to tech pro — start learning today.