项目中常用的js方法(持续更新)

<script>
        var utils = {
            //时间戳转日期(timestamp:时间戳 默认当前时间)
            dateFormat: function(timestamp = new Date().getTime()){
                let date = (new Date(timestamp + 8 * 3600 * 1000));
                return date.toJSON().replace("T", " ").substr(0, 19);
            },
            //数组排序去重(arr:数组,sequence:正序/倒序 默认正序)
            arrFromat: function(arr, sequence = "z"){
                if(sequence == "z"){
                    return [...(new Set(arr.sort(function(a, b){ return a - b})))];
                }else{
                    return [...(new Set(arr.sort(function(a, b){ return b-a})))];
                }
            }
        }
</script>

猜你喜欢

转载自www.cnblogs.com/muou2125/p/11082455.html