function type(target){ var ret=typeof(target); var template={ "[object Array]":"array", "[object Object]":"object", "[object Number]":"number-object", "[object Boolean]":"boolean-object", "[object String]":"string-object", } if(target==null){ return 'null'; } if(ret=='object'){ var str=Object.prototype.toString.call(target); return template[str]; }else{ return ret; } }
var obj1=[{a:1},{b:2},{c:3},{d:4}]
type(obj1) //"array"
type(new String('123')) //"string-object"