[RESOLVED] simple 2 dim array and 3 dim array in javascript/error
Results 1 to 5 of 5

Thread: [RESOLVED] simple 2 dim array and 3 dim array in javascript/error

  1. #1
    Senior Member
    Join Date
    Aug 2009
    Posts
    365

    resolved [RESOLVED] simple 2 dim array and 3 dim array in javascript/error

    I get the error message below in scratchpad upon hitting the page which I don't understand why.

    Code:
    <html>
    <script>
    var pr_arr = function(){
    
    
    var arr[0] = new array(1,2,3);
     arr[1] =new array("jr","ch","mh");
     arr[2] = new array('color',1,2);
    
     vardump(arr);
    }
     var pr_arr1 = function(){
    
    var arr =[[1,2),["jr","ch"],['color',1]];
    
     alert(arr[0][0]);
    
     }
    
     pr_arr();
     pr_arr1();
     </script>
     </html>
    Exception: missing ; before statement
    @Scratchpad/2:6
    */
    /*
    Exception: missing ; before statement
    @Scratchpad/2:6
    */
    thanks,

  2. #2
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,844
    Code:
    var arr[0] = new array(1,2,3);
    You can't declare (using var) just one element of an array. Declare the array, and then put things in it.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

  3. #3
    Senior Member
    Join Date
    Aug 2009
    Posts
    365
    Quote Originally Posted by Weedpacket View Post
    Code:
    var arr[0] = new array(1,2,3);
    You can't declare (using var) just one element of an array. Declare the array, and then put things in it.
    thanks,

  4. #4
    Senior Member
    Join Date
    Aug 2009
    Posts
    365
    I am getting another error after I declared the array? I got two different ones so the compiling got confused.
    /*
    Exception: Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMWindow.alert]
    @7
    */var pr_arr = function(){
    var arr = new Array();
    arr[0] = {1,2,3};
    arr[1] ="{jr","ch","mh"};
    arr[2] = {'color',1,2};

    alert(arr.join('\n'));
    }
    pr_arr();





    /*
    Exception: missing : after property id
    @Scratchpad/2:5
    */
    */

  5. #5
    Pedantic Curmudgeon Weedpacket's Avatar
    Join Date
    Aug 2002
    Location
    General Systems Vehicle "Thrilled To Be Here"
    Posts
    21,844
    Exception: missing : after property id
    Code:
      arr[0] = {1,2,3};
    You're trying to set arr[0] to an object literal without naming any of its properties. You presumably meant to use an array literal.
    THERE IS AS YET INSUFFICIENT DATA FOR A MEANINGFUL ANSWER
    FAQs! FAQs! FAQs! Most forums have them!
    Search - Debugging 101 - Collected Solutions - General Guidelines - Getting help at all

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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