📜  Lodash _.bitwiseLeft() 方法

📅  最后修改于: 2022-05-13 01:56:35.805000             🧑  作者: Mango

Lodash _.bitwiseLeft() 方法

Lodash是一个基于 underscore.js 的 JavaScript 库。 Lodash 有助于处理数组、字符串、对象、数字等。

_.bitwiseLeft() 方法用于返回对所有给定参数使用按位左运算符(<<) 的结果。

句法:

_.bitwiseLeft( val1, val2,..., valn )

参数:此方法采用可变数量的参数并对它们进行按位左运算符。

返回值:此方法返回对所有参数使用按位左运算符的结果。

注意:这在普通 JavaScript 中不起作用,因为它需要安装 lodash.js contrib 库。 Lodash.js contrib 库可以使用npm install lodash-contrib 安装

示例 1:

Javascript
// Adding lodash-contrib library 
var _ = require('lodash-contrib'); 
  
// Using the _.bitwiseLeft() method
var bL  = _.bitwiseLeft( 1, 3, 5, 7, 9 ); 
    
console.log("The bitwiseLeft is :", bL);


Javascript
// Adding lodash-contrib library 
var _ = require('lodash-contrib'); 
  
// Using the _.bitwiseLeft() method
var bL  = _.bitwiseLeft( 1, 3, 2 );
    
console.log("The bitwiseLeft is :", bL);


Javascript
// Adding lodash-contrib library 
var _ = require('lodash-contrib'); 
  
// Using the _.bitwiseLeft() method
var bL  = _.bitwiseLeft( 1 ); 
    
console.log("The bitwiseLeft is :", bL);


输出:

The bitwiseLeft is : 16777216

示例 2:

Javascript

// Adding lodash-contrib library 
var _ = require('lodash-contrib'); 
  
// Using the _.bitwiseLeft() method
var bL  = _.bitwiseLeft( 1, 3, 2 );
    
console.log("The bitwiseLeft is :", bL);

输出:

The bitwiseLeft is : 32

示例 3:

Javascript

// Adding lodash-contrib library 
var _ = require('lodash-contrib'); 
  
// Using the _.bitwiseLeft() method
var bL  = _.bitwiseLeft( 1 ); 
    
console.log("The bitwiseLeft is :", bL);

输出:

The bitwiseLeft is : 1