看看这个代码:在最后一行,它显示[] why??
const arrcodces =[1,2,3,4]
const arrOfPWs=[]
const data=[]
const arrOfPWs_2=[]
const base=[
'2','3','4','5','6','7','8','9',
'a','b','c','d','e','f','g','h','i',
'k','m','n','p','q','r','s','t','u',
'v','w','y','z','+','=','*','.','/'
]
//********************************* */
for(let i=0;i<arrcodes.length;i++){
let pw=''
for(let j=0;j<6;j++){
pw=pw+base[Math.floor(Math.random()*base.length)]
}
data.push(pw)
}
for(let i=0;i<arrcodes.length;i++){
arrOfPWs.push({code:arrcodes[i],password:data[i]})
}
//********************************* */
async function loopy(element) {
const newPW = await bcrypt.hash( element.password, 3)
arrOfPWs_2.push({code:element.code,password:newPW})
}
function doIt() {
arrOfPWs.forEach(el =>
loopy(el)
)
}
doIt()
//********************************* */
console.log(arrOfPWs_2)//SHOWS [] !!!
我试过了,在控制台.log()底部显示[]!!...............................................................
1条答案
按热度按时间bxgwgixi1#
1.调用异步函数loopy而不等待。