The elements in the js array are date strings. How can they be duplicated and sorted? Solve

var array = ["2018-03-05, 2013-06-12, 2019-03-12, 2018-03-05, 2014-02-22];
wants to de-weight and sort the previous array

Apr.07,2021

var arr = ['2018-03-05','2013-06-12','2019-03-12','2018-03-05','2014-02-22'];
var arr1 = [...new Set(arr)]
var sortedarr = arr1.sort((a,b)=>{
                return a>b
             }) 
console.log(sortedarr)



var times = {}
array.forEach(function(item) {
    var time = new Date(item).getTime()
    if (!times[time]) {
        times[time] = true
    }

})

var arrTimes = Object.keys(times).sort(function(a, b){return a - b })

and then you just reformat it


Menu