question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Usage in Express - date values passed to getting converted to strings

See original GitHub issue

I’m fairly new to Express and ejs, but I have a project where an array of objects is passed to res.render(), including a date property (represented as a JS Date object).

I can see in the debugger the date values are objects when passed in, but in the template they are converted into strings and in the original array/object dates are similarly mutated. Is it possible that ejs does this, or is it a hidden feature of Express?

// before
[{name: string, date: Date}, {name: string, date: Date}]

// after render
[{name: string, date: string}, {name: string, date: string}]

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
robationscommented, Jul 21, 2017

This turned out to be some middleware that had been installed (express-promise) mutating objects passed to the response object in express. Sorry about the extra noise.

1reaction
robationscommented, Jul 13, 2017

Nice one-liner 😃 Okay, I will try to eliminate components one by one, seems like there is some “magic” somewhere. Thanks for your info.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL Server functions for converting a String to a Date
In this article, we will learn about SQL Server convert String to Date functions like CAST(), TRY_CAST(), CONVERT(), TRY_CONVERT() and ...
Read more >
Parsing a string to a date in JavaScript - Stack Overflow
Just concatenate your date string (using ISO format) with "T00:00:00" in the end and use the JavaScript Date() constructor, like the example below....
Read more >
Convert a String to a Date object in JavaScript | bobbyhadz
Use the Date() constructor to convert a string to a Date object, e.g. const date = new Date('2022-09-24') . The Date() constructor takes...
Read more >
Date - JavaScript - MDN Web Docs - Mozilla
Chrome Edge Date Full support. Chrome1. Toggle history Full support. Edge12. Toggle hist... @@toPrimitive Full support. Chrome47. Toggle history Full support. Edge15. Toggle hist... Date() constructor...
Read more >
JavaScript Date toString() Method - GeeksforGeeks
The date.toString() method is used to convert the given date object's contents into a string.The date object is created using date() ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found