# \_.clamp（求夹值）

**语法：**

```javascript
_.clamp(number, [lower], upper)
```

**源代码链接：**[source](https://github.com/lodash/lodash/blob/4.17.10/lodash.js#L13980)

**npm包链接：**[npm package](https://www.npmjs.com/package/lodash.clamp)

**描述：**

返回限制在`lower`和`upper`之间的值。

**开始版本：**&#x34;.0.0

**参数：**

* `number (number)`: 被限制的值。
* `[lower] (number)`: 下限。
* `upper (number)`: 上限。

> 个人理解觉得应该取一个上上限一个下限，然后取三个值的中间夹值。没用过

**返回值：**

* `(number)`: 返回被限制的值。

**例子：**

```javascript
_.clamp(-10, -5, 5);
// => -5

_.clamp(10, -5, 5);
// => 5
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://lodash.shujuwajue.com/number/clamp.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
