Lodash _.mul() 方法
Lodash是一个基于 underscore.js 的 JavaScript 库。 Lodash 有助于处理数组、字符串、对象、数字等。
_.mul() 方法用于返回所有给定参数的乘积。
句法:
_.mul( val1, val2, ..., valn )
参数:此方法采用可变数量的值来查找产品。
返回值:此方法返回所有给定参数的乘积。
注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash contrib 库。 Lodash contrib 库可以使用npm install lodash-contrib –save 安装。
示例 1:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.mul() method
var mulVal = _.mul( 8, 22, 10 );
console.log(
"The Product of given values is :", mulVal
);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.mul() method
var mulVal = _.mul( 8 );
console.log(
"The Product of given values is :", mulVal
);
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.mul() method
var mulVal = _.mul( 0.8, 0.2, 0.9 );
console.log(
"The Product of given values is :", mulVal
);
输出:
The Product of given values is : 1760
示例 2:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.mul() method
var mulVal = _.mul( 8 );
console.log(
"The Product of given values is :", mulVal
);
输出:
The Product of given values is : 8
示例 3:
Javascript
// Defining lodash contrib variable
var _ = require('lodash-contrib');
// Using the _.mul() method
var mulVal = _.mul( 0.8, 0.2, 0.9 );
console.log(
"The Product of given values is :", mulVal
);
输出:
The Product of given values is : 0.14400000000000004