Lodash教程

Lodash clamp method

语法

_.clamp(number, [lower], upper)
Clamps number within the inclusive lower and upper bounds.

参数

number (number) − The number to clamp. [lower] (number) − The lower bound. upper (number) − The upper bound.

输出

(number) − Returns the clamped number.

实例

var _ = require('lodash');
var result = _.clamp(-12,-2, 2);
console.log(result);
result = _.clamp(12,-2, 2);
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

-2
2
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4