實際上(引自《JavaScript “Associative Arrays” Considered Harmful》):
There is no way to specify string keys in an array constructor. //在數組構造函數中無法定義字符串鍵值JavaScript arrays (which are meant to be numeric) are often used to hold key/value pairs. This is bad practice. Object should be used instead.
//大意:數組只支持數字的,鍵值對應使用于對象上。
擴展閱讀:
《Javascript Array Fun》2、可使用 “The Miller Device” 方法來判斷是否是數組
代碼如下:擴展閱讀:
《The Miller Device》 《isArray: Why is it so bloody hard to get right?》新聞熱點
疑難解答
圖片精選