0
我想寫來檢查,如果該鍵屬於「計數」類別的函數:爲什麼下面的「in」運算符沒有在這個數組中找到字符串?
isCountKey (key) {
const countKeys = [
'buildingCount',
'panoramaCount'
] // TODO find a better way to check for count keys
console.log(key)
console.log(key in countKeys)
return key in countKeys
}
console.log
然而,總是返回false
,即使關鍵是buildingCount
和panoramaCount
:
name
List.vue?2658:38 false
List.vue?2658:42 number
List.vue?2658:38 false
List.vue?2658:42 buildingCount
List.vue?2658:38 false
List.vue?2658:42 panoramaCount
List.vue?2658:38 false
這是爲什麼?
您有一個數組,其作爲數字索引...使用對象..'countKeys = {[ 'buildingCount':真實, 'panoramaCount':真 }' –
,因爲這裏的鍵是0和1 – Alexander
或使用'countKeys .indexOf(key)!= -1' –