利用Object.prototype.toString.call(val)判斷數據類型

利用Object.prototype.toString.call(val)判斷數據類型

返回值會以下列形式返回:

1. null => "[object Null]"
2. undefined => "[object Undefined]"
3. true => "[object Boolean]"
4. 1 => "[object Number]"
5. '' => "[object String]"
6. [] => "[object Array]"
7. {} => "[object Object]"
8. function () {} => "[object Function]"
9. new Date() => "[object Date]"
10. /./ =>  "[object RegExp]"
11. Math => "[object Math]"
12. Math.max() => "[object Number]"
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章