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
    New Coder mentalhorse's Avatar
    Join Date
    Jul 2005
    Location
    Duanesburg, NY
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Refurring to Arrays using *.length

    Hello. I am trying to make a number variable that takes the number of the amont of information in an array. 0bviously,

    So here is my code involved.
    // Below is the actualy array
    function motherShip() {
    var pain_in_butt = new Array();
    for (index=0;index < number_of_rows;index++) {
    pain_in_butt[index] = "<br />" }
    }
    // Bolded is where I try to refer to the .length of the pain_in_butt array
    function theMath() {
    var index_a = pain_in_butt.length;
    for (index5=0;index5<index_a;index5++){
    document.write("testing"); }
    }
    I am farely new to Javascript. I have tried putting document.pain_in_butt.length.
    Why is a raven like a writing desk?

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,634
    Thanks
    0
    Thanked 649 Times in 639 Posts
    If you define the array inside motherShip then it will be deleted when that function ends and is undefined after that. To keep it define it outside of the function like this:

    // Below is the actualy array
    var pain_in_butt = new Array();
    function motherShip() {
    for (index=0;index < number_of_rows;index++) {
    pain_in_butt[index] = "<br />" }
    }
    // Bolded is where I try to refer to the .length of the pain_in_butt array
    function theMath() {
    var index_a = pain_in_butt.length;
    for (index5=0;index5<index_a;index5++){
    document.write("testing"); }
    }
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    New Coder mentalhorse's Avatar
    Join Date
    Jul 2005
    Location
    Duanesburg, NY
    Posts
    89
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thank you very much. I thought I tried that, but I guess not.
    It now works.
    Why is a raven like a writing desk?


  •  

    Posting Permissions

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