【发布时间】:2021-12-09 08:35:17
【问题描述】:
我正在尝试使用 Google Apps 脚本获取 Google 群组中的人员列表。我做了一个代码(如下),但结果出乎意料。我认为与项目的格式有关,但不确定。在我的代码中,我测试了许多日志来检查。
为什么“indexOf”不能正确检测到电子邮件?因为 -1.00 作为答案是错误的。
信息: getUsers() User[] 检索具有已知相应 Google 帐户的组的直接成员。
我认为当我用“”询问时 indexOf 回答 -1.00 并且当我用数组的位置正确回答时回答是奇怪的。
如果有人在此组内(在循环内),我需要签入脚本。
function CheckingSomeFromGroup() {
var members = GroupsApp.getGroupByEmail("members@company").getUsers();
Logger.log(members); //it shows an array in the log
Logger.log(members[0]); //it shows the first element form that array which is "Jorge@company.com"
Logger.log(members.indexOf("Jorge@company.com") //i was expecting a number different than -1.00 because jorge exists but in the log appear -1.00 which is wrong
Logger.log(members.indexOf(members[0]); //it shows 0 correctly becuase Jorge is in the first place of the array
Logger.log(members.length);//it shows number 3 which is ok since i have 3 people in the group
}
【问题讨论】:
-
members是一个对象。使用.findIndex(e =>e.getEmail()==='Jorge@company.com') -
@TheMaster 惊人的答案!效果惊人!真的谢谢!
标签: javascript google-apps-script google-developers-console google-groups-api