Results 1 to 12 of 12

Thread: Javascript: test if an object is an array.

Threaded View

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2006
    Posts
    27

    Javascript: test if an object is an array.

    Hi! I would like to know if there is an elegant way to test if an object is an array.

    Example:
    Code:
    function ProcessObject(object) {
      //Test if it is an array.
      if(...) {
        for(int i=0; i < object.length; i++) {
          //object[i] ...
        }
      }
      else {
        //Don't process as an array.
        //object.value  ...
      }
    }
    In the code above, the function is receiving an object that could be an array or not. The main reason I want to know if it is an array is because I want to use the length property. Do anyone know if there is a property in DOM to know if an object is an array so I can invoke the length property without error?

    Thanks a lot!

    PS: I make it, in a not elegant way...
    Last edited by Tribo; Mar 25th, 2008 at 03:56 PM.

Posting Permissions

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



Click Here to Expand Forum to Full Width