Open In App

Lodash _.bitwiseAnd() Method

Last Updated : 29 Sep, 2020
Improve
Improve
Like Article
Like
Save
Share
Report

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc.

The _.bitwiseAnd() method is used to return the result of using the Bitwise AND (&) operator on all the given arguments.

Syntax:

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

Parameters: This method takes a variable number of parameters and operates the Bitwise AND operator on them.

Return Value: This method returns the result of using the Bitwise AND operator on all the arguments.

Note: This will not work in normal JavaScript because it requires the lodash.js contrib library to be installed. Lodash.js contrib library can be installed using npm install lodash-contrib –save.

Example 1:

Javascript




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


Output:

The bitwiseAnd is : 1

Example 2:

Javascript




// Adding lodash-contrib library 
var _ = require('lodash-contrib'); 
  
// Using the _.bitwiseAnd() method
var bA  = _.bitwiseAnd( 1, 3, 4, 6 ); 
    
console.log("The bitwiseAnd is :", bA);


Output:

The bitwiseAnd is : 0

Example 3:

Javascript




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


Output:

The bitwiseAnd is : 1


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads