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

109
Visualizações
Unexpected array behavior when passed through EJS in Express

I have an array of Strings in my users.js which I render to my ejs page and then there is an onclick method where it is passed to a js function like below users.js

console.log("count ",count);
res.render("index2", {title: 'some data', imgsrc : variabled, coun : count});

and index2.ejs

<button onclick="popu('<%= coun %>');">

and popu() is

function popu(coun) {
    var select = document.getElementById("selectNumber");

    for(var i = 0; i < coun.length; i++) {
        var opt = coun[i];
        var el = document.createElement("option");
        el.textContent = opt;
        el.value = opt;
        select.appendChild(el);
    }
}

So, basically it is filling a drop-down menu. The problem is that console.log(count) consoles this

count  [
  'Forest', 'Ocean',
  'Port', 'Airport',
]

but the drop-down menu is

F
o
r
e
....

And I am unable to get why is the array iterating over these strings too.

Note: the count array was formed by pushing mongodb query results like this

var count = [];

var arr = await coll.find().toArray();
    for(var i=0; i<arr.length; i++) {
        val = String(arr[i].Name)
        count.push(val);
    }

Any help is appreciated

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