經常會在js裏用到數組,比如 多個名字相同的input, 若是動態生成的, 提交時就需要判斷其是否是數組.
typeof的運算數未定義,返回的就是 "undefined".
運算數爲數字 typeof(x) = "number"
字符串 typeof(x) = "string"
布爾值 typeof(x) = "boolean"
對象,數組和null typeof(x) = "object"
函數 typeof(x) = "function"
typeof 運算符返回一個用來表示表達式的數據類型的字符串。
可能的字符串有:"number"、"string"、"boolean"、"object"、"function" 和 "undefined"。
如:
alert(typeof (123));//typeof(123)返回"number"
alert(typeof ("123"));//typeof("123")返回"string"
typeof 運算符
返回一個用來表示表達式的數據類型的字符串。
typeof[()expression[]] ;
expression 參數是需要查找類型信息的任意表 達式。
說明
typeof 運算符把類型信息當作字符串返回。typeof 返回值有六種可能: "number," "string," "boolean," "object," "function," 和 "undefined."
typeof 語法中的圓括號是可選項。
轉載:http://blog.163.com/liguiqin_500/blog/static/763064201041395742250/