Usage in Express - date values passed to getting converted to strings
See original GitHub issueI’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:
- Created 6 years ago
- Comments:7
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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.
Nice one-liner 😃 Okay, I will try to eliminate components one by one, seems like there is some “magic” somewhere. Thanks for your info.