Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert "['2022-03-24', '2022-03-25']" to javascript array

I want to convert "['2022-03-24', '2022-03-25']" to javascript array data is from element.dataset

did const dateRange = JSON.stringify("['2022-03-24', '2022-03-25']")
JSON.parse(dateRange) returns ['2022-03-24', '2022-03-25'] which is a string and not a javaScript array.

I want to populate date range with flatpickr with object from my database so I’m passing the date html element via data attribute <input type="date" class="date-range" data-date="{{date_range}}" />

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Try that, it would leave you with array of date strings, try to parse them to dates now (if you need).

someString.replace(/[',\]\[]/g, '').split(' ')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading