問題: 利用typeof操作符對Null、Array、Object作用返回的都是object類型,區分不開。
方法:?
? ? ? ?1??: instanceof?
? ? ? ? ? ? ? ? ? ?[] instanceof Array? ? ?//true
? ? ? ? ? ? ? ? ? ?{}instanceof Object? ? ?//true
? ? ? ? ? ? ? ? ? ? null === null? ? ? ? //true
? ? ? ? ?2??: constructor
? ? ? ? ? ? ? ? ? ? [].constructor === Array? ? //true
? ? ? ? ? ? ? ? ? ? {}.constructor === Object? ? //true
? ? ? ? ? ? ? ? ? ? null === null? ? ?//true
? ? ? ? 3??:length屬性
? ? ? ? ? ? ? ? ? [2,3].length ? ? ?//2.
? ? ? ? ? ? ? ? ? {}.length ? ? ? ? ? ?//undefinded
? ? ? ? ?4??:ES5 ? isArray()方法
? ? ? ? ? ? ? ? ? ?Array.isArray([]) ? ? ? ?//true
? ? ? ? ? ? ? ? ? ?Array.isArray({}) ? ? ? ?//false
注意:函數arguments是對象不是數組,