# \_.toLength(value)

URL: https://caijiao.org/lodash/docs/Lang/_.toLength
Source: docs/lodash/docs/Lang/_.toLength.md
Description: 将值转换为有效的数组长度。

`_.toLength(value)` 用于将值转换为有效的数组长度。

- `value`：要转换的值。

返回值：转换后的有效的数组长度。

示例：

```javascript
console.log(_.toLength(3.14)); // 输出：3
console.log(_.toLength("3.14")); // 输出：3
console.log(_.toLength(Infinity)); // 输出：4294967295
console.log(_.toLength(-Infinity)); // 输出：0
console.log(_.toLength("abc")); // 输出：0
console.log(_.toLength(null)); // 输出：0
console.log(_.toLength(undefined)); // 输出：0
```

在这个例子中，`_.toLength` 将值转换为有效的数组长度。如果值是有效的数组长度，则返回相应的值；如果值是 Infinity、-Infinity、NaN 或无法转换为数字的字符串，则返回 0。
