我试图通过循环(JS)注册100个用户到firebase与给定的电子邮件和密码列表 .
但很少有人已经存在,很少有人的电子邮件格式错误 . 因此,如果 user email already registered or is badly formatted ,我写的脚本会抛出异常 . 我想跳过该用户的注册并继续下一个注册 .
如果异常发生,如何跳过循环 .
for (var i = 0; i < data.length; i++){
//Variables of email and password
if (email !== '' && email !== undefined) {
const promise = firebase.auth().createUserWithEmailAndPassword(email, password)
.then(function(response) {
console.log(response.uid);
});
promise.catch(function(e){
console.log(e.message);
//Skip and continue to next iteration
});
}
}
1 回答
你可以使用Promise.all: