Friday, October 24, 2025
HomeLanguagesJavascriptLodash _.without() Method

Lodash _.without() Method

The _.without method creates a new array in a filtered form that is there are values to exclude and give new values as output.
Note: It is dissimilar to _.pull() method, this method returns a new array.

Syntax:

_.without(array, [values])

Parameters: This method accepts two parameters as mentioned above and described below:

  • array: This parameter holds the array to inspect.
  • [values]: This parameter holds the values to exclude.

Return Value: This method returns the new array of filtered values.

Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.

javascript




// Requiring the lodash library 
const _ = require("lodash"); 
      
// Original array 
var w = _.without([3.2, 5.2, 
       5.2, 1.2], 5.2, 3.2);    
  
// Use of _.without() method
let gfg = _.without(w);
      
// Printing the output 
console.log(gfg);


Output:

[ 1.2 ]

Example 2:

javascript




// Requiring the lodash library 
const _ = require("lodash"); 
      
// Original array 
var w = _.without([3, 5, 5, 1], 1, 3);    
var t = _.without([4, 7, 4, 8], 7, 4);
  
// Use of _.without() method
let gfg = _.without(w);
let gfg1 = _.without(t);
      
// Printing the output 
console.log(gfg);
console.log(gfg1);


Output:

[ 5, 5 ]
[ 8 ]

Example 3:

javascript




// Requiring the lodash library 
const _ = require("lodash"); 
       
// Original array 
var w = _.without(['a', 'b', 
        'c', 'b' ], 'a', 'b'); 
var x = _.without(['C++', 'Java', 
    'Python', '.Net' ], 'C++', 'Java');
   
// Use of _.without() method
let gfg = _.without(w);
let gfg2 = _.without(x);
       
// Printing the output 
console.log(gfg);
console.log(gfg2);


Output:

[ 'c' ]
[ 'Python', '.Net' ]

Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.

RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS