Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

94
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda