Function: isEmpty

isEmpty(val): boolean

判断值是否为空 如果值是空对象、空集合、空字符串、空数组或任何不被视为集合的类型,则返回 true。

https://30secondsofcode.org/type#isempty

Parameters

Name Type Description
val unknown 要检查的值

Returns

boolean

是否为空

Example

isEmpty([]); // => true
isEmpty({}); // => true
isEmpty(''); // => true
isEmpty([1, 2]); // => false
isEmpty({ a: 1, b: 2 }); // => false
isEmpty('text'); // => false
isEmpty(123); // => true - 数字类型不被视为集合
isEmpty(true); // => true - 布尔类型不被视为集合
isEmpty(new Map()); // => true
isEmpty(new Set()); // => true
ON THIS PAGE