1

I'm working with Handlebars in an Express application. From the server-side I'm passing an array of dates as strings:

reqCtrl.dateController = async (req, res) => {
...
var dates = [
    "2020-09-27",
    "2020-09-28",
    "2020-09-29",
    "2020-09-30",
    "2020-10-01",
    "2020-10-02",
    "2020-10-03",
    "2020-10-04",
  ];

  console.log(dates);
  //Resulting in: ['2020-09-27', '2020-09-28', '2020-09-29', '2020-09-30', '2020-10-01', '2020-10-02', '2020-10-03', '2020-10-04']
  res.render("requests/...", 
    dates
  });
}

However, on the client side, with the following expression I get different values.

<script>
console.log({{ dates }})
//Resulting in:  1984 1983 1982 1981 2009 2008 2007 2006
</script>

Am I missing something? How can I render the correctly formatted date?

1
  • The issue was that it was subtracting the numbers rather than showing the string Commented Oct 29, 2021 at 13:46

1 Answer 1

1

What would happen if you rendered <p>{{dates}}</p>, instead of console logging it? Either way, you will likely want to iterate through arrays to render when using handlebars. This is done with #each.

<ul>
  {{ #each dates}}
    <li>{{this}}</li>
  {{/each}}
</ul>
  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.