我正在收集資料,這是來自 mongoDB 的問題,我將其放入一組隨機問題中。該集合不接受輸入,并且回傳空。
module.exports.java = async (req, resp) => {
// const choice = req.body;
let quest = [];
let option = [];
let sort =[];
try {
let data = await Questions.find({ type: 'javascript'})
//for creating an array of questions
data.forEach((elements) => {
//Stores all the string in an array
quest.push(elements.description);
option.push(elements.options);
})
const unique = new Set()
for (let i =0; i<10;i ){
let rand = Math.floor(Math.random()*20 0);
let input = quest[rand]
unique.add(input);
// console.log(typeof quest[rand])
console.log('Inside the loop, quest: ' input)
console.log('Inside the loop, unique: ' unique)
}
resp.send(unique)
}catch(e) {
console.log(e)
}
uj5u.com熱心網友回復:
它可能正在作業,但是當它被 JSON 化時,一個 Set 可以被轉換成一個空物件。也就是說,JSON 中的 Set 沒有“標準”表示,因此您會得到一個“{}”。首先將其轉換為陣列:
resp.send(Array.from(unique));
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/388144.html
標籤:javascript 节点.js 表达
