0

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.

Bubi
  • 1
  • 3
  • This has been asked before. See: https://stackoverflow.com/a/64419864/3397771 – 76484 Nov 05 '21 at 19:27
  • Does this answer your question? [How to pass an object to a .handlebars template and use it in a javascript code block?](https://stackoverflow.com/questions/64407740/how-to-pass-an-object-to-a-handlebars-template-and-use-it-in-a-javascript-code) – 76484 Nov 08 '21 at 19:24

0 Answers0