【发布时间】:2020-02-01 10:01:45
【问题描述】:
我正在尝试使用 firebase 云函数将地图转换为数组
这是我的代码。
let map = new Map();
map.set("1", 1);
map.set("2", 2);
console.log(new Array(...map).map(pairs => pairs[0]));
// Upper code not relevant: just to test, but prints ["1", "2"] in the firebase logs)
const getUser = await admin.firestore()
.collection("users")
.doc(context.auth.uid)
.get();
let userMap = getUser.data()['friendsMap'];
console.log(userMap);
// Prints this in the firebase logs: { '1234ab': 'Jeff',
5678ab: 'Bob' }
let userIDLIST = new Array(...userMap).map(pairs => pairs[0]);
console.log('userIDLIST:'+userIDLIST);
当我想将 userMap 转换为 userIDLIST 数组(最后一行代码)时,我收到错误:
Unhandled error TypeError: undefined is not a function
我做错了什么?
提前致谢!
【问题讨论】:
标签: typescript firebase google-cloud-firestore google-cloud-functions