Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post

    how do you get the amount of non null variables an array

    how do you get the amount of non null variables an array.
    In my example, I use x.length , but that gives the length of the entire array, how do I get it to tell me how many have been filled

    var x = new Array(10)
    x[0] = "blah blah blah''
    x[1] = "ha ha ha"
    x[2] = "I dont care"
    alert(x.length)
    although this gives me what I dont want which is 10
    I want it to tell me 3
    Kris Hubby
    kwhubby site

  • #2
    Regular Coder
    Join Date
    Sep 2002
    Location
    Louisiana
    Posts
    576
    Thanks
    0
    Thanked 0 Times in 0 Posts
    you could make a loop like this
    x = 0
    for (i=0, i<a.length, ++i) {
    if (a[i] != "") ++x
    }
    that should give the number of values of that are not null or undefined
    <edit> you might have to change "" to "undefined" the objects aren't null because you made them, just not defined yet.</edit>
    Last edited by chrismiceli; 11-08-2002 at 05:53 AM.

  • #3
    Regular Coder
    Join Date
    Nov 2002
    Location
    Carmel California
    Posts
    471
    Thanks
    0
    Thanked 1 Time in 1 Post
    yah ok thanks, I was hoping there was a really simple way such as x.notnulllength or something , but oh well Ill just use a for statement. Thanks, alot
    Kris Hubby
    kwhubby site


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •