Lodash _.div() 方法
Lodash _.div() 方法执行除法运算并返回所有给定参数的商。
句法:
_.div( val1, val2,..., valn )
参数:该方法取n个值并对其进行操作_.div()方法。
返回值:此方法返回所有给定参数的商。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用npm install lodash-contrib –save 安装。
示例 1:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var divVal = _.div( 8, 2, 1 );
console.log("The Quotient of given values is :", divVal);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var divVal = _.div( 16, 2, 4, 1 );
console.log("The Quotient of given values is :", divVal);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var divVal = _.div( 1, 2, 4, 1 );
console.log("The Quotient of given values is :", divVal);
输出:
The Quotient of given values is : 4
示例 2:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var divVal = _.div( 16, 2, 4, 1 );
console.log("The Quotient of given values is :", divVal);
输出:
The Quotient of given values is : 2
示例 3:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
var divVal = _.div( 1, 2, 4, 1 );
console.log("The Quotient of given values is :", divVal);
输出:
The Quotient of given values is : 0.125