how to use the pullallby function from lodash in javascript

To use the pullAllBy function from the Lodash library in JavaScript, follow these steps:

  1. Import the function from the Lodash library:
index.tsx
const pullAllBy = require('lodash/pullAllBy');
47 chars
2 lines
  1. Call the pullAllBy function with three arguments:
index.tsx
const arr = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
const values = [{ 'x': 1 }, { 'x': 3 }];
const iteratee = 'x';
const result = pullAllBy(arr, values, iteratee);
console.log(result); // [{ 'x': 2 }]
211 chars
6 lines

The first argument is the array from which you want to remove elements. The second argument is an array of values that should be removed. The third argument is the property name that should be used to compare elements.

In the example above, the pullAllBy function removes the first and third objects from the arr array, since they have x property values that are also present in the values array, and returns a new array with only the second object.

gistlibby LogSnag