我在firestore中有一个数据库字段,其中有一个这样的地图:
坐标:{_ 01:“铜”,_02:“金”,_03:“铁”}
我在Firestore管理面板中看到此数据库,如下所示: pic
当我尝试使用以下代码列出项目
data.cordinates.map((item, i)=>
console.log(i+" - "+item)
);
我收到:
Unhandled Rejection (TypeError): data.cordinates.map is not a function
读/写这种地图的正确方法是什么?
btw console.log(data.cordinates)给我这样的输出:
{_01: "copper", _02: "gold", _03: "iron", _04: "", _05: "", …}
_01: "copper"
_02: "gold"
_03: "iron"
_04: ""
_05: ""
_06: ""
_07: ""
_08: ""
_10: ""
_11: ""
_12: ""
_13: ""
_14: ""
_15: ""
_16: ""
_17: ""
_18: ""
_20: ""
_21: ""
_22: ""
_23: ""
_24: ""
_25: ""
_26: ""
_27: ""
_28: ""
_30: ""
_31: ""
_32: ""
_33: ""
_34: ""
_35: ""
_36: ""
_37: ""
_38: ""
_40: ""
_41: ""
_42: ""
_43: ""
_44: ""
_45: ""
_46: ""
_47: ""
_48: ""
是的,总共有48个元素
非常感谢您的帮助。
答案 0 :(得分:1)
将map
更改为forin
这是示例代码:
const cord = data.cordinates || {} // to handle undefined `data.cordinates` case
for(let i in cord){
if(cord.hasOwnProperty(i)){
const item = cord[i];
console.log(i+" - "+item);
// do your other stuff here
}
}