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

116
Views
Accessing handlebars object variable via javascript

I am using this code on the server side

app.get('/private', requiresAuth(), function (req, res) {
...
    res.render('private', {ListOfLoggedUsers: ListOfLoggedUsers});

What am I sending to the client is an array of objects which looks like this

[
  {
    userid: 'npwtest2',
    useridtimestamp: '2021-11-05T15:44:15.516Z',
    latitude: undefined,
    longitude: undefined
  },
  {
    userid: 'npwtest3',
    useridtimestamp: '2021-11-05T15:44:30.028Z',
    latitude: 15.7855745,
    longitude: 15.9264816
  },
  {
    userid: 'npwtest2@malinator.com',
    useridtimestamp: '2021-11-05T15:45:12.515Z',
    latitude: 55.7855745,
    longitude: 15.9264816
  }
]

On the client side I am using handlebars to access this variable:

<div>
        {{#each ListOfLoggedUsers}}
        <div class="row">
            <div class="col-md-12">
                <p>Logged user id: {{userid}}, Login date: {{moment useridtimestamp     format="DD.MM.YYYY HH:mm:ss"}},
                    Latitude: {{latitude}}, Longitude: {{longitude}} </p>
           </div>
        {{/each}}
</div>

This part is working fine, I am getting output which I want

I am trying to access those ListOfLoggedUsers from inline java script but without any success

<script>

var loggedUser = {{ListOfLoggedUsers}}

or 

var loggedUser = [{{ListOfLoggedUsers}}];
console.log (loggedUser)
    
</script>

Any idea how can access this array of objects inside inline javascript ? Thanks in advance.

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!