Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Javascript Array

Options
  • 20-10-2010 9:43am
    #1
    Registered Users Posts: 4,037 ✭✭✭


    I have a problem with a javascript array I am using. I am adding it to a combo box but it adds "undefined" to the very end of the array (which then appears at the end of the combo box).
    It doesn't appear in the source of the page, I have tried removing it with push() and loads of other ways but nothing works.
    Has anyone come across this before?


Comments

  • Registered Users Posts: 2,781 ✭✭✭amen


    can you post some code?


  • Registered Users Posts: 4,037 ✭✭✭lukin


    amen wrote: »
    can you post some code?

    I have decided to give up on using an array. I wnat to split a string into substrings based on commas without using an array.

    edit; I got it

    You can't actually remove it from the array, I had to remove it from the drop down I was adding it to, like so:

    if (typeof a1 == 'undefined') {
    element.options = null;


  • Registered Users Posts: 2,781 ✭✭✭amen


    I think JavaScript supports split.

    look it up


  • Registered Users Posts: 1,127 ✭✭✭smcelhinney


    lukin wrote: »
    I have decided to give up on using an array. I wnat to split a string into substrings based on commas without using an array.

    edit; I got it

    You can't actually remove it from the array, I had to remove it from the drop down I was adding it to, like so:

    if (typeof a1 == 'undefined') {
    element.options = null;

    I would probably worry more about why an "undefined" value is making it into the array in the first place. Trace it back, saves you doing error handling in multiple places.

    Also, you can remove items from Javascript arrays using array.splice. Google's your friend on this one.


  • Registered Users Posts: 4,037 ✭✭✭lukin


    I would probably worry more about why an "undefined" value is making it into the array in the first place. Trace it back, saves you doing error handling in multiple places.
    I would if I had time. The array is being populated by a javascript responsetext so some weird stuff probably got in there.
    Also, you can remove items from Javascript arrays using array.splice. Google's your friend on this one.

    I tried spilt(), it worked for separarating out the response text into an array wherever there is a comma but it still put undefined into the end of the array.


  • Advertisement
  • Registered Users Posts: 2,781 ✭✭✭amen


    if you are getting undefined you have something wrong somewhere.

    you need to fix that first


Advertisement