Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
Set is not taking in a string in JavaScript

I am getting a collection of a data, which is questions from mongoDB, and I putting that in a set of random question. The set is not taking the input, and it is returning empty.

 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)
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It's probably working, but a Set can get converted into an empty object when it's getting JSONed. That is, there's no "standard" representation for a Set in JSON, so you get a "{}". Convert it into an array first:

resp.send(Array.from(unique));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!