Front end: determine the number of digits in strings, arrays, and numbers

1. Determine the length of the array. The simplest. length is fine

var arr=[1,2]
arr.length=2

2. The length of the string can also be directly .length

let strs='123213'
 console.log(atrs.length);//6

3. The length of the number

  var event = 1234567890; //判断的数
 var count = 0;//计位数
    while (event >= 1) {
      event = event / 10;
      count++;
    }

输出:count==10

Guess you like

Origin blog.csdn.net/weixin_47194802/article/details/132299260