在js中可以使用Object.prototype.toString.call()的来检测一个对象是否为一个数组
//检测数组 var a = [1, 2]; console.log(typeof a); //object console.log(Object.prototype.toString.call(a)); //[object Array] //检测字符串 var s = "you"; console.log(typeof s); //string console.log(Object.prototype.toString.call(s)); //[object String]