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

108
Views
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
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!