tags:

views:

84

answers:

3

In javascript is there a good(i mean built in) way that i can find whether element if array of not ? one simple i can see is as follows but i don't like it

if(ele.push){//its array it has push method :) }

I mean i would like know if something like below if exists. typeof made me upset as its returning "object" (though that makes sense)

function x(ele){ if(isArray(ele)){//dosomething} }
A: 
element.constructor == Array
Matchu
+1  A: 

http://www.andrewpeace.com/javascript-is-array.html

<script type="text/javascript">
  function is_array(input){
    return typeof(input)=='object'&&(input instanceof Array);
  }
</script>
Pepper
A: 

Not the cleanest but...

function isArray(obj) {
    return obj.constructor == Array;
}
byte