Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
how to create array with push in node.js

I will be select my data from MySQL then I loop this result and then I create an array with push. but I got two results after creating the array. the first array is empty and the second result is normal.

this is my code

app.all("/social-feed-reply", isUserAllowed, function (req, res) {
  // console.log('......here');
  // console.log(req.query);
  // console.log('.......new test');
  // console.log(req.query.id);
  var sql = "  SELECT * FROM books WHERE book_id IN(?) ";
  db.query(sql, [req.query.id, 0], function (err, result, fields) {
    if (err) throw err;
    //here  is i got normal result
    var newArrays = [];
    Object.keys(result).forEach(function (key) {
      newArrays.push(result[key].book_id);
    });
    console.log(newArrays);
    //when is console the newArrays then i got two result  exemple :[] [ 7, 5 ]
  });
});

how can I remove the empty array?

enter image description here

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda