📜  Lodash _.isLength() 方法

📅  最后修改于: 2022-05-13 01:56:20.640000             🧑  作者: Mango

Lodash _.isLength() 方法

Lodash _.isLength() 方法检查给定值是否是类似数组的长度并返回相应的布尔值。

句法:

_.isLength( value )

参数:此方法接受上面提到的单个参数,如下所述:

  • value:此参数保存需要检查类似数组长度的值。

返回值:此方法返回一个布尔值(如果给定值是类似数组的长度,则返回 true,否则返回 false)。

示例 1:

Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
// Checking for Length
console.log("The Value is Length : "
        + _.isLength(100));


Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
// Checking for Length 
console.log("The Value is Length : "
        + _.isLength(Infinity));


Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
// Checking for Length 
console.log("The Value is Length : "
        + _.isLength("len"));


Javascript
// Defining Lodash variable 
const _ = require('lodash'); 
  
// Checking for Length 
console.log("The Value is Length : "
        + _.isLength(Number.MAX_VALUE));


输出:

The Value is Length : true

示例 2:对于 Infinity,它返回 false。

Javascript

// Defining Lodash variable 
const _ = require('lodash'); 
  
// Checking for Length 
console.log("The Value is Length : "
        + _.isLength(Infinity));

输出:

The Value is Length : false 

示例 3:对于字符串,它返回 false。

Javascript

// Defining Lodash variable 
const _ = require('lodash'); 
  
// Checking for Length 
console.log("The Value is Length : "
        + _.isLength("len"));

输出:

The Value is Length : false 

示例 4:

Javascript

// Defining Lodash variable 
const _ = require('lodash'); 
  
// Checking for Length 
console.log("The Value is Length : "
        + _.isLength(Number.MAX_VALUE));

输出:

The Value is Length : true