3👍
✅
An easy way to to this is split
the string by the character "-"
to an array which we reverse
and join
it togheter with "-"
.
Or use moment if you have it installed already.
// result step 1
console.log('2022-10-25'.split("-"));
// result step 2
console.log('2022-10-25'.split("-").reverse());
// final result
console.log('2022-10-25'.split("-").reverse().join("-"));
// with moment.js
console.log(moment('2022-10-25').format("DD-MM-YYYY"));
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.4/moment.min.js"></script>
3👍
Can’t you simply reverse the string?
const dates = ['2022-10-25']
const desiredDate = dates[0].split('-').reverse().join('-')
Source:stackexchange.com