“This is the 7th day of my participation in the Gwen Challenge in November. Check out the details: The Last Gwen Challenge in 2021.”

## 1. Null value judgment

`. Args Usage of remaining parameters`

``1. The residual argument syntax allows us to represent an indefinite number of arguments as an array. 2. If the last named argument of a function begins with... Is prefixed, it will become an array,Copy the code``

The elements from 0 (inclusive) to theargs.length (excluded) are supplied by the actual arguments passed to the function.

``````isNullOrBlank(. args){
for(let i=0; i<args.length; i++){let argument=args[i];
if(argument===null||argument===' '||argument===undefined) {return true; }}return false;
}
Copy the code``````

## 2. Keep X decimal places

NaN() method: NaN attributes are special values that represent non-numeric values. This property is used to indicate that a value is not a number. You can set the Number object to this value to indicate that it is not a numeric value.

``````formatDecimal(number,x){
let value="-"; x=x? x:1;
if(! isNullOrBlank(number)){if(!NaN(number)){
if(String(number).indexof('. ') > -1) {// number is a decimal number
if(x==0){
value=Math.round(number);
}else{
value=Math.round(number * Math.pow(10,x))/Math.pow(10,x); }}else{
// Number is an integer
value=parseFloat(number); }}}}Copy the code``````

## 3. Force X decimal places to remain

``````forceFormatDecimal(number,x){
let value=formatDecimal(number,x);
if(value! =The '-'){ value=value.toFixed(x); }}Copy the code``````

NumberObject.toFixed(num)

The toFixed() method rounds the Number to a specified decimal Number.

## 4. Keep two decimal places

The isNaN() function is used to check whether its arguments are non-numeric values.

isNaN(x)

If x is a special non-numeric value NaN (or can be converted to such a value), the value returned is true. If x is any other value, return false.

``````keepTwoDecimal(value){
let reg=/^\d+(.\d+)? \$/;
if(reg.test(value)){
if(! isNullOrBlank(value)){if(!isNaN(value)){
let split=String(value).split('. ');
if(split.length>1&&split[1].length>0){
split[1]=split[1].substring(0.2);
value=split.join('. '); }}}}else{
value=value.replace(/[^\d.]/g.' ');
}
return value;
}
Copy the code``````

## 5. Convert the yyyyMMdd time format to YYYY-MM-DD

``````// An extension to Date that converts Date to a String of the specified format
// Year (y) can use 1-4 placeholders, month (M), day (d), hour (h), minute (M), second (s) can use 1-2 placeholders, week (w), millisecond (s) can only use 1 placeholder
/ / (new Date ()). The Format (' yyyy/MM/dd w) = = = > 2020/01/01 Wednesday
/ / (new Date ()). The Format (' MM - dd yyyy - hh: MM: ss. 'S) = = = > 2020/01/01 08:05:06. 666
/ / (new Date ()). The Format (' yyyy - M - d h: M: s.S ") = = = > 2020-1-1 8:5:6. 666
Copy the code``````
``````Date.prototype.Format=function(fmt){
var o={
'M+':this.getMonth()+1.'d+':this.getDate(),
'h+':this.getHours(),
'm+':this.getMinutes(),
's+':this.getSeconds(),
S:this.getMilliseconds()
};
var week=['day'.'一'.'二'.'三'.'four'.'five'.'六'];if(/(y+)/.test(fmt)){
fmt=fmt.replace(RegExp. \$1,this.getFullYear()+' ').substr(4-RegExp.\$1.length);
}
if(/(w)/.test(fmt)){
fmt=fmt.replace(RegExp. \$1,'week'+week[this.getDay()]);
}
for(var k in o){
if(new RegExp('(' + k + ') ').test(fmt)){
fmt=fmt.replace(RegExp. \$1,RegExp.\$1.length==1?0[k]:('00'+o[k]).substr((' '+o[k]).length)); }}return fmt;
}
Copy the code``````